Posts

Showing posts from January, 2014

The value and usage of Dollar $ in UNIX/LINUX and shell scripting

Image
Scenario1: Dollar($) can be used to get the value of user-defined variable and also system-defined variables like HOME,LOGNAME,PATH,PS1,IFS,SHELL etc.. [root@localhost ~]# x=18 [root@localhost ~]# echo $ x 18 [root@localhost ~]# echo $ PATH /usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost ~]# Scenario2:$PS1 Some times when you login to a particular user(other than root -> since root always has prompt #)of  UNIX/LINUX server the prompt appears as Dollar($) it’s because of the primary Prompt String(PS1) has been set a like below  .If you  want you can change it as your customized prompt. [root@localhost ~]# echo $PS1 [\u@\h \W]\ $ [root@localhost ~]# su - bharath [bharath@localhost ~] $ Scenario3->$0: $0 gives the name of the shell or shell script. "$0" gives the running script name with absolute path. If you want only the  script name you have to use  basename $0 whic