#!/bin/bash
echo " hello " # say hello to the user
echo " $HOME "
echo " $HOSTNAME "
echo " $(uname) "
echo " today is $(date) "
echo " $(whoami) is currently logged in "
now my question is how to change the code so that the info is not displayed but sent to a file ?
I know its a basic thing for you but I am just beginning here so looking forward for your response . .. . .
thanks
vi 006
i
#!/bin/bash
echo " hello " # say hello to the user
echo " $HOME "
echo " $HOSTNAME "
echo " $(uname) "
echo " today is $(date) "
echo " $(whoami) is currently logged in "
:wq
"006" [New file] 7 lines, 184 characters
an12:/home/vbe $ chmod 750 006
an12:/home/vbe $ ./006 > 006.out
an12:/home/vbe $ more 006.out
hello
/home/vbe
an12
AIX
today is Fri Nov 18 16:43:17 NFT 2011
vbe is currently logged in
006.out: END
In your code, if FILE does not exist, the script creates it (an empty FILE) and exit. You'll have to run your script twice to have what you expect. I don't know if it's a wanted behaviour.
If you redirect (>>) every time your script runs, the content of all your commands will be appended at the end of the FILE. If you want to start with a fresh FILE every time your script runs, you have to redirect (>) the first echo so FILE won't grow up in size.
Sure, group your commands between { (don't forget the space or new line just after) and } (don't forget space, semi-colon ( or new line just before) and redirect (>) to FILE.
#!/bin/sh
{
echo " hello "
echo " $HOME "
echo " $HOSTNAME "
echo " $(uname) "
echo " today is $(date) "
echo " $(whoami) is currently logged in "
} > "$1"
exit 0