#!/bin/csh -f # strip_trailing_slash # ------------------------------------------------------------------------------ # Shell script to strip the trailing slash off of a filename. Reads a filename # (optionally with a full path) from the command line or stdin and echos it # without any trailing slash. # ------------------------------------------------------------------------------ # Assumptions: # Effects: # - Echoes filename to stdout # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ------------------------------------------------------------------------------ if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [filename || filename/]" echo "Example: $0:t abd.def" echo "Example: $0:t abc.def/" echo "Example: $0:t /Users/fred/" exit 1 endif # Get the arg from the command line or stdin if ($#argv == 0) then set name = $<:q else set name = $1:q endif # Get length of name in chars (-m), using -n to prevent trailing newline. @ numchars = `echo -n $name:q | wc -m` # Reduce length by one to skip trailing slash, if any set lastchar = "`echo $name | cut -c $numchars`" if ("$lastchar" == "/") @ numchars-- # Echo the name w/o any trailing slash. echo $name:q | cut -c 1-$numchars