Pages

Thursday, September 27, 2012

Difference between $variable and ${variable} in (bash) shell scripting

Many often we do shell scripting, but small small ignorance at times cost a lot. Here is an example of what we mean and what it become.
[/tmp]$ cat try.sh #! /bin/sh a=12 b=34 echo $a_$b echo ${a}_$b [vivarkey@/tmp]$ sh try.sh 34 12_34 [/tmp]$


In the above shell script we intended to print "variableA_variableB", in the shell script on last but one line. But since we missed the braces around the variable it actually truncated the previous variable along with the '-' symbol.

NB: This code snippet is tried in bash shell on Linux, on mac it gives different result.

HTH
Kongkon

Playing with RPM

Ever wondered after running the rpm --install (or rpm -ivh) command what happened, what sort of files created in the file system.

To find out the list of files that an already installed rpm spawned:
rpm -ql
NB: there is no .rpm after the package name here in this command.

[root@localhost release]# rpm -qa|grep lsifw-tools-xrtx
lsifw-tools-xrtx-1-1.xrtx.1872.noarch
[root@localhost release]# rpm -ql lsifw-tools-xrtx-1-1.xrtx.1872.noarch
/lib/firmware/lsi/.NOT_RELEASE_DIR
/lib/firmware/lsi/FirmwareID.sh
/lib/firmware/lsi/xrtx_lsifw.sh
/usr/share/man/man8/xrtx_lsifw.8.gz
[root@localhost release]# 



To find out the list of files that an rpm will generate once you install the rpm:
rpm -qlp

[root@localhost tmp]# rpm -qlp /tmp/lsifw-tools-xrtx-1-1.xrtx.1872.src.rpm
lsifw-tools-xrtx-source.spec
lsifw-tools-xrtx.tgz
[root@localhost tmp]#


HTH
Kongkon