how to find last selected character in shell script -
i have assigned following string variable.
line="/remotepath/mypath/localpath/common/location.txt"
if want access common location (/remotepath/mypath/localpath/common) how can split in last "/" ?
in unix-style operating systems, there's program called dirname
you:
$ line="/remotepath/mypath/localpath/common/location.txt" $ dirname "$line" /remotepath/mypath/localpath/common
the command of course available shell, since it's not part of shell per-se, though might need assign variable differently. example, in csh/tcsh:
% setenv line "/remotepath/mypath/localpath/common/location.txt" % dirname "$line" /remotepath/mypath/localpath/common
if want strip off file using shell commands alone, you'll need specify shell you're using, since commands vary. example, in /bin/sh or similar shells (like bash), use "parameter expansion" (look in man page, there's lots of stuff):
$ line="/remotepath/mypath/localpath/common/location.txt" $ echo "${line%/*} /remotepath/mypath/localpath/common
Comments
Post a Comment