You are not logged in.

#1 2009-08-09 06:28:39

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Starting Execution At A Certain Point In A Shell Script

Im working on a script that will do the stage 2 installation for me and its kind of a pain to have to run the whole script again just to see if something that I fixed at the very end was actually fixed. Is there a GOTO command or something like that that will let me skip certain chunks of the script? (ex. place GOTO line 128 at line 5 so I dont have to wait X amount of minutes for it to get there)

Offline

#2 2009-08-09 06:55:06

xd-0
Member
From: Sweden
Registered: 2007-11-02
Posts: 327
Website

Re: Starting Execution At A Certain Point In A Shell Script

Make a function in your script tat you call when needed.

#function
showhiddenfiles() { ls -a }

#calling the function
showhiddenfiles

Offline

#3 2009-08-09 10:32:12

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: Starting Execution At A Certain Point In A Shell Script

Yeah it appears Bash at least doesn't support any form of GOTO, either you can comment what you don't want to run, or you might be able to put the undesired code into a function and then just not call it, much like xd-0's response

Offline

#4 2009-08-09 11:43:01

foutrelis
Developer
From: Athens, Greece
Registered: 2008-07-28
Posts: 705
Website

Re: Starting Execution At A Certain Point In A Shell Script

You can put "labels" in comments and use sed to pass only the part of the script you want to be executed to bash. This won't work well if there are required functions defined above the starting line.

For example:

cookies.sh:

#!/bin/bash

echo cookies
echo ice cream

#tacos
echo tacos

In ~/.bashrc:

bgoto() {
    sed -n "/^#$1\$/,\$ p" "$2" | bash
}

And finally run the script starting at #tacos with:

[foutrelis@foutboxd ~]$ bgoto tacos cookies.sh 
tacos

It's not pretty, but it should do what you want. tongue

Last edited by foutrelis (2009-08-09 11:46:06)

Offline

#5 2009-08-09 20:32:16

HashBox
Member
Registered: 2009-01-22
Posts: 271

Re: Starting Execution At A Certain Point In A Shell Script

@foutrelis, that's a handy trick big_smile

Offline

#6 2009-08-10 00:58:34

m1sha
Member
Registered: 2009-04-23
Posts: 9

Re: Starting Execution At A Certain Point In A Shell Script

You could run tail on the script and feed that to bash, if you knew how long it was going to be, that is.

Offline

#7 2009-08-10 16:53:52

brando56894
Member
From: NYC
Registered: 2008-08-03
Posts: 681

Re: Starting Execution At A Certain Point In A Shell Script

Thanks for the responses but I found a way to block comment stuff using

:<<'END'
commented stuff here
END

Offline

Board footer

Powered by FluxBB