程序将输出设置为2位小数浮点数,文件中每行一个.根据执行情况,可以输出许多文件,每个文件的文件名为cancer.ex#,其中#是程序从脚本执行的次数.
教授提供了一个awk脚本作为使用gnuplot生成95%置信度图表的第一步.我想将输出转换为格式
conf $1 $2 $3 var#
其中#是来自cancer.ex的数字#
我开发了以下内容:
#!/bin/bash
Files=Output/*
String
for f in $Files
do
String="conf "
cat $f | while read LINE
do
String="$LINE "
done
echo $String
done
Run Code Online (Sandbox Code Playgroud)
我知道缺少一些步骤,因为我刚刚开始将它们放在一起.我的问题是执行连接部分,因为它根本不起作用.执行上面的脚本时没有输出,nada.但是,如果我String="$LINE
改为echo $LINE
,那么我将获得放在终端上的文件的所有输出.
bash中循环中的变量是否有可行的附加函数?
我已经看过几个这样的帖子,就像这个,但没有人在我的特殊情况下帮助我.
scriptsPath="/var/db/gbi/scripts/"
echo "$scriptsPathawesome.csv";
Run Code Online (Sandbox Code Playgroud)
我希望这会回应 /var/db/gbi/scripts/awesome.csv
相反,我得到了 .csv
好像它认为我正在尝试引用一个名为的变量$scriptsPathawesome
.如何将$scriptsPath
变量连接到"awesome.csv"
字符串文字?
我对 unix bash 脚本很陌生,需要知道这是否可行。我想多次询问用户的输入,然后将该输入存储到一个变量中。
userinputs= #nothing at the start
read string
<code to add $string to $userinputs>
read string
<code to add $string to $userinputs> #this should add this input along with the other input
Run Code Online (Sandbox Code Playgroud)
因此,如果用户在第一次询问时输入“abc”,则会在 $userinputs 中添加“abc”
然后当再次询问输入并且用户输入“123”时,脚本应将其存储在相同的 $userinputs 中
这将使 $userinput=abc123
我正在尝试printf
按照此处的示例使用 bash 连接字符串:
$ printf "%s " "hello printf" "in" "bash script"
Run Code Online (Sandbox Code Playgroud)
以上工作。但是当我尝试将一些破折号 ( -
)添加到格式字符串时:
$ printf "--file=%s " "hello printf" "in" "bash script"
Run Code Online (Sandbox Code Playgroud)
它产生一个错误:
sh: printf: --: 无效选项
显然,它将格式字符串视为一个选项。如何-
在输出中包含破折号?
(我试图添加 use\-
来逃避破折号,但无济于事。)
鉴于以下陈述:
ac_reg_ids="-1" #Starting value
(mysql) | while read ac_reg_id; do
echo "$ac_reg_id" #variable is a result of a mysql query. Echoes a number.
ac_reg_ids="$ac_reg_ids, $ac_reg_id" #concatenate a comma and $ac_reg_id, fails.
done
echo "ac_reg_ids: $ac_reg_ids" #echoes -1
Run Code Online (Sandbox Code Playgroud)
现在根据这个答案:https://stackoverflow.com/a/4181721/1313143
连接应该有效.但是为什么不呢?循环中有什么不同?
以防万一它可能很重要:
> bash -version
> GNU bash,版本4.2.8(1)-release(i686-pc-linux-gnu)
使用set -eux输出:
+ echo 142
142
+ ac_reg_ids='-1, 142'
+ read ac_reg_id
Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Keycloak 端点获取身份验证令牌并使用它来访问另一个资源。获取令牌不是问题,但将其传递到另一个请求的标头中却是一项不可能的任务,至少在单个命令中是这样:
curl \
-X POST \
-d 'client_id=app' \
-d 'username=username' \
-d 'password=password' \
-d 'grant_type=password' \
-d "client_secret=$APP_SECRET" \
'http://localhost:9000/auth/realms/realm/protocol/openid-connect/token' \
| \
jq -r '.access_token' \
| \
curl \
-X GET \
-H "Accept: application/json" \
-H "Authorization: Bearer @-" \ # <- read header value from stdin
-u "username:password" \
"http://localhost:8080/app/api/"
Run Code Online (Sandbox Code Playgroud)
实现这一目标的替代方法是什么?
我想以编程方式将小占位符替换为静态内容,如用户名或工作路径.
在bash中是否有可能动态执行我的perl替换状态,如:
GROUPNAME="$(id -g -n $USER)"
perl -pi -e 's/\(PLACEHOLDER\)/' + "$GROUPNAME" + '/g' filepath/file
Run Code Online (Sandbox Code Playgroud)
如果我还能为占位符调整这种动态行为,那将是非常好的.但首先要做的事情.如何连接这些字符串?