我在网上的 bash 脚本教程中遇到了以下 while 循环:
while(($#)) ; do
#...
shift
done
Run Code Online (Sandbox Code Playgroud)
我不明白在 while 循环中使用位置参数基数。我知道该shift命令的作用,但是 while 语句与shift?
我已经使用 @PropertySource 和 @Value 注释来读取外部文件属性,并且效果很好。但是,如果我想将相同的 @Value 注释属性写入外部文件,可以这样做吗?我已经做了一些搜索,但似乎无法找到一种方法。是否有本地支持?
我有以下非常简单的脚本:
#!/bin/bash
checkCmdLineArgs() {
echo -e "num input args $#"
if (( $# == 0 )); then
echo "$0 usage: install_dir home_dir"
exit 255
fi
}
checkCmdLineArgs
Run Code Online (Sandbox Code Playgroud)
这是行不通的.如果我像这样运行它:
./test.sh foo bar
Run Code Online (Sandbox Code Playgroud)
它输出:
num input args 0
./test.sh usage: install_dir home_dir
Run Code Online (Sandbox Code Playgroud)
知道为什么会失败吗?
我的 bash 脚本中有以下一行:
echo "foo" | awk -F"=" '{char=system("echo $1 | cut -c1");}{print "this is the result: "$char;}' >> output.txt
Run Code Online (Sandbox Code Playgroud)
我想使用 awk 打印“foo”的第一个字母,这样我会得到:
this is the result: f
Run Code Online (Sandbox Code Playgroud)
在我的输出文件中,但相反,我得到:
this is the result: foo
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?谢谢