bash scripting
Results 1 to 3 of 3

Thread: bash scripting

  1. #1
    Senior Member
    Join Date
    Oct 2001

    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.

    file1 contains

    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.

    Whats a \"START\" button?

  2. #2
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    for i in `cat file1`
    echo "hello $i >> file2";

    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...



    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

    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  3. #3
    Senior Member
    Join Date
    Oct 2001
    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.
    Whats a \"START\" button?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts