Bash Scripting

1. How to deference a variable in Bash. Suppose we have i=10;j=i

bash$ echo ${!j} – will give 10

2. Rename extensions of files from “.doc to .txt”. This can be done in many ways:

bash$ ls -1 | sed ‘p;s/\.doc/\.txt/’ | xargs -n2 mv

Using, extraction – bash$ i=a.txt; echo ${i/.txt} – will return “a”

Using basename command – bash$ basename a.txt .txt – will retrun “a”

Leave a Reply

Your email address will not be published. Required fields are marked *