Scripting queries - Newbie
Hi,
I have a file containing a list of commands with argument, how to run the commands automatically? Assuming the contents of file "command2run" are as follows: ls -ls ls -la ls -L I tried the following: for i in `cat command2run` do $i done The arguments were ran seperately instead of "ls -ls". Please advise? Thanks in advance. |
Ok ... a few things:
1. Please use [code][/code] tags around code and data 2. Do not use a for loop to read a file as it will under go word splitting (which is why you see separate entries). Use a while loop 3. If you are looking to execute the items in the file you can source it, ie use source or . prior to file name on the command line Code:
$ . command2run |
Hi,
I used . command2run but it just not able to go back to the command prompt after it finished. Not even I do and control-c. |
Then use "source" Or a little help for you to use while to read a file:
Code:
while read line; do <do something here with $line>; done< input_filename |
Ok, not sure what to tell you as it works as described for me.
However, here are some assumptions I have made which may be incorrect: 1. Your standard shell is bash, to check: Code:
$ echo $SHELL Code:
$ cat command2run Code:
$ . command2run |
run it with sh command directly
Quote:
|
All times are GMT -5. The time now is 10:54 AM. |