小编njk*_*015的帖子

什么 while(($#)); 做 ...; 转移; done 在 bash 中是什么意思,为什么有人会使用它?

我在网上的 bash 脚本教程中遇到了以下 while 循环:

while(($#)) ; do
   #...
   shift
done
Run Code Online (Sandbox Code Playgroud)

我不明白在 while 循环中使用位置参数基数。我知道该shift命令的作用,但是 while 语句与shift?

parameters bash while-loop

4
推荐指数
2
解决办法
5126
查看次数

使用 spring boot 编写文件属性

我已经使用 @PropertySource 和 @Value 注释来读取外部文件属性,并且效果很好。但是,如果我想将相同的 @Value 注释属性写入外部文件,可以这样做吗?我已经做了一些搜索,但似乎无法找到一种方法。是否有本地支持?

spring properties

3
推荐指数
1
解决办法
2802
查看次数

从函数内部检查脚本命令行参数

我有以下非常简单的脚本:

#!/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

2
推荐指数
1
解决办法
37
查看次数

如何在awk中打​​印系统命令的结果

我的 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)

我究竟做错了什么?谢谢

bash awk

2
推荐指数
1
解决办法
1608
查看次数

标签 统计

bash ×3

awk ×1

parameters ×1

properties ×1

spring ×1

while-loop ×1