shell脚本中的问题
尝试此选项,
#!/bin/ksh
echo $1
awk '{FS="=";print $2}' $1
我正在命令行上
test_sh INSTANCE=VIJAY
但 awk 失败。这里有什么问题吗? 基本上我需要在命令行上传递的值VIJAY
。
I am trying this option
#!/bin/ksh
echo $1
awk '{FS="=";print $2}' $1
and on the command line
test_sh INSTANCE=VIJAY
but awk is failing. Is there any problem here?
Basically I need the value VIJAY
passed on the command line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
ksh(和 Bash)可以为您进行拆分:
运行它:
ksh (and Bash) can do the splitting for you:
Running it:
对于
awk
,第二个参数是要处理的文件的名称。所以你要求它处理名为
INSTANCE=VIJAY
的文件相反,做
只是为了清楚起见,它的作用是将要处理的输入通过标准输入通过管道从
回声
;而不是 awk 从文件中读取输入。引用 Awk 手册:
for
awk
, the second parameter is a name of the file to process.So you asked it to process the file named
INSTANCE=VIJAY
Instead, do
Just to be clear, what this does is pass the input to be processed to awk via standard input through a pipe from output of
echo
; instead of awk reading it input from a file.To quote from Awk manual:
我认为更简单的是
cut
也可以在等号上分割,然后显示第二个标记。另请注意,将$1
传递给awk
不正确,因为该参数不是文件。I think a simpler one is
as
cut
can split on the equal sign as well and then show the second token. Also note that the passing$1
toawk
was not correct as that argument is not a file.我认为你离开了管道 (|)
替代方案
I think you left the pipe (|)
Alternative