To simplify my bash loop script
Hi folks.
I'd like to make a simplified loop script,like #!/bin/sh while true do command1;command2;command3 sleep $somevariabl done in that case I can only type like #./loop.sh command1;command2;command3 somevariable. how could I achieve this? |
The code:
Code:
#!/bin/sh Code:
./loop.sh "command1" "command2" "command3" "sleep_time" Do read man page of bash. Also there are basic as well as advanced BASH guides available from TLDP. |
thanks for your response.
But in the first place I don't know how many commands I would pass to the script. So it looks not like a perfect form. Quote:
|
So you can pass sleep_time as first parameter and the commands as next. And use a loop to execute the commands one by one.
|
Quote:
if I use a loop to execute the commands one by one,in what way I could pass those commands to the script? since I don't know how many commands I would pass to. |
You use a shell feature which gives user a count of how many positional parameters (arguments) were passed.
|
Quote:
for var in "$@" do echo "$var" done |
I found some problem in those things.
Code:
> bash -x ./2.sh ls "ls |wc" "ls ~" "seq 1 3" "seq 1 3|wc" Can someone help me? |
|
If you actually want to execute arbitrary shell commands (not just single programs), you should use eval:
Code:
for var in "$@" |
All times are GMT -5. The time now is 01:49 PM. |