Reputation: 8729
Hi I have a small script (script name is: test1.sh) that looks like this
PRG=$0
data=`expr $PRG : '.*\/.*'`
echo $data
When I run this I see output as
10
I could not understand the regular expression written in the second line of the script. What would that mean?
Upvotes: 1
Views: 195
Reputation: 98108
The expression returns a non-zero value if there is a /
within the relative filename of the script ($0 in sh
). If you execute the script like this: sh ../../script.sh
, it outputs 15, which is the total length of "../../script.sh". It matches "../../" with '.*\/
and matches script.sh
with the .*
part.
Upvotes: 1