[英]Edit a variable from a simple linux script using Bash
I have that simple script there, what I would like to do is edit that A variable to output 5 when I run ./prA.sh from bash.我在那里有那个简单的脚本,我想要做的是在我从 bash 运行 ./prA.sh 时编辑该变量以输出 5。
But I would like to know how to do it via command line, or bash.但我想知道如何通过命令行或 bash 做到这一点。 I don't want to edit the Script using Vi or any other editor.
我不想使用 Vi 或任何其他编辑器编辑脚本。
If I understood your question right, you have some options to solve your problem, here I will show two.如果我理解你的问题,你有一些选择来解决你的问题,这里我将展示两个。
$ chmod +x test.sh
$ cat test.sh
#!/bin/bash
A=${1} # here you will receive the "aloha", showed in example below
echo $A
$ ./test.sh "aloha"
aloha
$ bash -x test.sh "aloha" # debugging bash scripts easily
+ A=aloha
+ echo aloha
aloha
# you can see in terminal A still empty, because you just
# passed "aloha" as argument/parameter to the bash script
$ echo $A
$ export A="aloha" # if you want A to be defined in terminal, export it
$ echo $A # now you have value directly in terminal
aloha
Tip: Don't paste images of your code, always insert directly code in the site using code blocks.提示:不要粘贴代码的图像,始终使用代码块在站点中直接插入代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.