Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Set variables in bash script

test.sh contains:

A=$1
B=$2

I set test.sh to chmod 777

I started the script with 2 parameters:

./test.sh first last

Then I tested it by typing:

echo "FirstVar: $A SecondVar: $B"

Result:

"FirstVar:  SecondVar: "

What did I do wrong?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When you run your script like this:

./test.sh whatever

Bash runs another instance of shell which interprets command in your script. If you want to set variables in the current shell, you should use source command, or dot (.). In this case the commands in the script will be executed in the current shell directly.

source test.sh

or just

. test.sh
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!