-
bash scripting
I need a little help on bash scripting. I want to be able to take a list of names from one file and output them to another but add extra text to it.
example
file1 contains
bob
joe
dave
paully
sally
file 2 will contain
hello bob
hello joe
hello dave
hello paully
hello sally
like that.
like echo "hello $name" >> file2
i know its probably going to be a loop but i lost the only book i had that showed the examples...i'm in the process of buying a new one but figured i give you guys/girls a try.
thanks.
-
for i in `cat file1`
do
echo "hello $i >> file2";
done
the backticks (` `) tell the shell to execute the command. cat will just lump them all together, the for reads the whitespace and saves each one in $i, which is why the echo references $i...
Gravy,
/neb
PS: Was thinking about it, you should probably avoid using 'bash' to do shell scripts. Stick with the standard of ksh or sh, it makes your stuff automagically more portable (and most everything in sh will work in bash). Don't forget to start your script off with #!/bin/sh
-
thanks, that did the trick.
I know bash isnt the greatest but its just a small server on a local network that just serves music, so i didnt realy want to mess with another shell.
but again, much thanks for the help.