Getting “command not found” while using cut on bash variable
本问题已经有最佳答案,请猛点这里访问。
我在bash脚本中有两个变量
1 2 | hostname="ab78ascsoadp003.abc.com" Loc=`$hostname | cut -c3,4` |
我收到错误
我试图使用
虽然您可以使用
1 2 | 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 expressionssource:
man bash
1 2 | hostname="ab78ascsoadp003.abc.com" Loc=$(cut -c3,4 <<<"$hostname") |
你错过了
1 | Loc=`echo $hostname | cut -c3,4` |