【发布时间】:2021-05-04 08:01:33
【问题描述】:
# !/bin/sh
echo "Enter file name:"
read fname
set ${ls -la $fname}
echo "The size of test.sh is $5 byte"
exit 0
我想编写一个可以在 linux shell 脚本中使用“set”命令打印文件大小的代码,所以我使用 ls -la 但它不起作用,我的终端只是在第 4 行显示“错误替换”。任何帮助请:)
【问题讨论】:
-
我认为您的意思是使用
$(),而不是${}。不过,不确定您想对ls和set的输出做什么。也许你的意思是set -- $(ls -la "$fname"),但那似乎是fragile。