浏览 linuxcommand.org 上的教程。我编写的每个脚本,即使是复制粘贴的,都无法运行。以下是我所做的:
gedit test_script.html
在 gedit 中:
#!/bin/bash
for filename in "$@"; do
result=
if [ -f "$filename" ]; then
result="$filename is a regular file"
else
if [ -d "$filename" ]; then
result="$filename is a directory"
fi
fi
if [ -w "$filename" ]; then
result="$result and it is writable"
else
result="$result and it is not writable"
fi
echo "$result"
done
然后我进入命令行:chmod 777 test_script.html
然后我执行:./test_script.html
它什么也没做?它没有发送错误,只是进入下一个命令提示符?
我肯定我在做一些蠢事?
答案1
该脚本正在寻找位置参数。因此,您需要像这样运行命令:
jtoscarson:~/Downloads$ bash test.sh ./ ./ is a directory and it is writable