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

188
Views
Command Not Found when assigning an integer variable from another script

To illustrate my issue and questions consider two scripts.

Script1.sh

#!/bin/sh
test=1
echo $test

Script2.sh

#!/bin/sh
$(Script1.sh)

When I run Script1.sh from the command line directly via ./Script1.sh it produces the desired output.

1

However when I run Script2.sh which calls Script1.sh, instead I get the following error message:

Script2.sh: line 1: 1: command not found

It thinks that the integer 1 is a command for some odd reason?

I found a cheap work around which is to set a variable from the first script and pass it to the second script as a parameter but I would like to understand why this is failing.

Also, when I changed my variables value from 1 to "some text", I would expect that my echo would print "some text" to the screen. But when I call Script2.sh (which ultimately just calls Script1.sh) it doesn't print the echo to the screen. Why is that, and how do I resolve it so I can see the echo output the same as if I would have called Script1.sh directly?

Any advice would be greatly appreciated.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're calling it wrong by using command substitution. Just use source or a subshell if you want it:

. ./Script1.sh
( ./Script1.sh )

The second one is a bit redundant since it will always run in another shell anyway, so this would make more sense instead:

( . ./Script1.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!