-1

enter image description here

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.

But I would like to know how to do it via command line, or bash. I don't want to edit the Script using Vi or any other editor.

Learner33
  • 111
  • 8
  • Confused, why can you not just do `A=5`. Or `export A=5` if you want to make it available to all child sessions initiated from the session you are in. – user7247147 Sep 25 '20 at 17:36
  • Did you try exploring command line arguments? You can pass command line arguments and then access them as `$0`, `$1`, `$2` and so on. I think this will give you a rough idea https://stackoverflow.com/questions/192249/how-do-i-parse-command-line-arguments-in-bash – Amit Singh Sep 25 '20 at 17:36
  • If you edit the script, the tool you use to do it is by definition an editor. This sounds like an XY problem. What do you actually want to do? – William Pursell Sep 25 '20 at 17:42
  • `echo()(printf 5); export -f echo; ./prA.sh` – jhnc Sep 25 '20 at 19:00

1 Answers1

0

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.

lucasgrvarela
  • 351
  • 1
  • 4
  • 9