I have a string that may or may not end with a '/' and would like to do something if it does not end in a slash. I have tried:
if "/home/test/blah/blah" | sed 's/\/$//'
then
echo "OK"
fi
but I think sed works on input streams only and not files. I am not a shell programmer of any kind and am having difficulty in finding infomation on such things.
$? holds the exit status. If the match was found, then the exit status is 0.
The -q flag is required so that in case of success, nothing is printed out.
The -E flag is allow regex matching. The $ denoted the end of the string. So "/$" denotes the end of string is a "/"
That's great thank you. I am a Java programmer and find shell scripting very difficult to get my head around. I couldn't get the solution provided by skar_a to work and so went with the one given by cfajohnson but thanks to all who replied.