I have two variables in a bash script
hostname="ab78ascsoadp003.abc.com"
Loc=`$hostname | cut -c3,4`
I am getting an error ab78ascsoadp003.abc.com: command not found
I am trying to use cut command
so that $Loc
gets 78
I have two variables in a bash script
hostname="ab78ascsoadp003.abc.com"
Loc=`$hostname | cut -c3,4`
I am getting an error ab78ascsoadp003.abc.com: command not found
I am trying to use cut command
so that $Loc
gets 78
While you can use cut
to achieve this, sometimes it is useful to stick to bash:
hostname="ab78ascsoadp003.abc.com"
Loc=${hostname:3:2}
${parameter:offset:length}
Substring Expansion. Expands to up to length characters of parameter starting at the character specified by offset. Iflength
is omitted, expands to the substring of parameter starting at the character specified byoffset
.length
andoffset
are arithmetic expressions <snip>source:
man bash