我有一个文件,里面有几个带有形状的路径:
directory1/directory2/directory3
我想将这些路径之一放在脚本外壳的变量中,以用作路径。
我试过了 :
name="`sed -n 2p file`"
但是我不能使用这样的命令: cd "../$name"
。我收到一条错误消息,说该文件夹不存在。
您是否知道如何在脚本上执行此操作?
用切,
name=`cut -f1 -d "/" file` # instead of f1 use f2 for directory2 and so on
像这样,
[root@giam46 ~]# cat sample.txt
Desktop/MEF_R400
[root@giam46 ~]# name=`cut -f1 -d "/" sample.txt`
[root@giam46 ~]# echo $name
Desktop
[root@giam46 ~]# cd /root/${name}
[root@giam46 Desktop]# pwd
/root/Desktop
[root@giam46 Desktop]# cd ..
[root@giam46 ~]# pwd
/root
[root@giam46 ~]#
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句