[英]command-line with variable, doesn't work
I have a script that uses awk with parameters but I can't find the right syntax to make it functionnal. 我有一个使用带有参数的awk的脚本,但是我找不到正确的语法来使其功能化。 May be could you help me ?
可以帮我吗? (under osx, terminal, zsh, command line)
(在osx,terminal,zsh,命令行下)
I get a variable who is the path name (it's a awk result) 我得到一个变量,该变量是路径名(awk结果)
path_dir="/picture/dir/' path_dir =“ / picture / dir /'
After, I ask this: 之后,我问这个:
awk -F"/" '{print $2}' $path_dir
But it doesn't work. 但这是行不通的。 I get:
我得到:
cant' open file $path_dir
My goal is to do this: 我的目标是这样做:
dir_name=awk -F "/" '{print $2}' $path_dir
Then, to use 然后,使用
$dir_name
But first, awk can't read my $path_dir
但是首先,awk无法读取我的
$path_dir
Any idea ? 任何想法 ?
Thank you 谢谢
try this: 尝试这个:
dir_name=$(awk -F'/' '{print $2}' <<<$path_dir)
this should assign dir_name
with picture
这应该为
dir_name
分配picture
尝试:
dir_name=`awk -F "/" '{print $2}' $path_dir`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.