Reputation: 667
I am unable to process the following shell script
#!/bin/sh
P= '/mnt/temp/'
echo $P
Q= `echo $P` | sed -e "s/^.*\(.\)$/\1/"
echo 'Q is' $Q
echo ${P%?}
I expect the output as
/mnt/temp/
Q is /
/mnt/tmp
[edit]
As a next step I want to update remove the trailing / in P so am trying
if ${Q} ="/"
then
echo in
P=${P%?}
fi
but on execution it says
/: Permission denied
Upvotes: 0
Views: 97
Reputation: 185760
Spaces are not allowed in variable assignation in shell, so :
#!/bin/sh
P='/mnt/temp/'
echo "$P"
Q=$(echo "$P" | sed -e "s/^.*\(.\)$/\1/")
echo "Q is $Q"
echo "${P%?}"
And use more quotes, see http://mywiki.wooledge.org/Quotes http://mywiki.wooledge.org/Arguments and http://wiki.bash-hackers.org/syntax/words
Upvotes: 5