I just started learning bash scripting. I created this small script:
echo "You are user $UID on $HOSTNAME"
echo "Your home directory is: $HOME"
echo "$HOSTNAME is running $OSTYPE"
and placed it in /usr/bin
directory. It runs fine if I use ./script-name.sh
but I want it to execute by just typing script-name
in all accounts. How do I do that? And How to put colors to the ouput text? And How can I put this script in MOTD so that whenever a user loggs in He gets this Info without having to type the command?
I think the color issue is handled pretty well with the link given above......
first of all, if you want the script named "script-name" and NOT "script-name.sh" ...... change the name....... "mv script-name.sh script-name"
Make sure it's executable ........ "chmod 755 script-name"
Assuming you put this script in /usr/bin ...... you should be able to launch it now by simply typing "script-name".
Alternatively you could also create an alias in your .bashrc file to do the same thing.
The alias would look something like
You would then have to re-source your .bashrc file to make it active with the command