Thanks! You put me onto something, and after a quick Google I came across a solution here. The following taken from the aforementioned site:
Code:
if [ -f $filename ] translates $filename - if it has spaces the shell "thinks" $filename
is really separate values with no spaces
if [ -f "$filename" ] translates $filename - if it has spaces the shell "thinks" $filename
is realy one single value, spaces included
if [ -f '$filename' ] does not translate filename - the shell takes the $ literally, not
as a shell token meaning return the value of a variable
So basically, my problem is solved by adding double quotes around the variable name:
Code:
$ temp='Fantastic work'
$ expr substr "$temp" 1 3
Fan
Bookmarks