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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -