shell的touch命令不能拼接路径吗?

touch $path$x"/"$txt1,结果只能执行到"/"之前

阅读 5.9k
2 个回答

可以啊:

[root@iZ11eorublsZ tmp]# x=a
[root@iZ11eorublsZ tmp]# y=b
[root@iZ11eorublsZ tmp]# touch $x"/"$y
touch: cannot touch `a/b': No such file or directory
[root@iZ11eorublsZ tmp]# mkdir a
[root@iZ11eorublsZ tmp]# touch $x"/"$y
[root@iZ11eorublsZ tmp]# ll a/b
-rw-r--r-- 1 root root 0 Aug  5 13:11 a/b

把你的几个变量值也同时给出来,包括你执行的结果

export mypath=/tmp
export subpath=/1
echo "$mypath$subpath/filename.txt"
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏