Reputation: 43
This is very simple. I am trying to set my variable in a second script. I have tried multiple ways but does not work. Hence all the commented out section. The first script you run IE:unit3.2a.sh 3 5 this would return 8. The second script should read the result as 8. I am using cygwin.
unit3.2a.sh '''
#!/bin/csh
set a = 0
set b = 0
set c = 0
@ a = $1
@ b = $2
@ c = $a + $b
echo $c
'''
unit3.sh '''
#!/bin/csh
a=$(~./unit3.2a.sh)
#below is all that don't work!
#instructors: a =~./unit3.2a.sh 2 200
#./unit3.2a.sh "2" "200"
#~./unit3.2a.sh 2 200
#=$(./unit3.2a.sh 2 200)
#=$(./unit3.2a.sh)+(2 200)
#$(./unit3.2a.sh 2 200)
#$(/home/Admin/unit3.2a.sh)
#$(/home/Admin/unit3.2a.sh 2 200)
#added echo $a to see if I wasnt seeing anything the echo text works fine but a variable does not read?
#set a='./unit3.2a.sh 2 200'
##set a=$(cat ./unit3.2a.sh 2 200)
#$ ./unit3.sh
#cat: 2: No such file or directory
#cat: 200: No such file or directory
#set a=$(~./unit3.2a.sh 2 200)
#a=$(~./unit3.2a.sh 2 200)
echo $a
echo "The result is: $a"
echo "Storing the results.............."
echo "Storing the result: $a" >> unit3.txt
echo "The script is over"
'''
Upvotes: 0
Views: 371
Reputation: 8476
please note that:
~./unit3.2a.sh
is referring to a specific file location
while ./unit3.2a.sh
is referring to the file in the current directory
the form $( command )
is bash specific, does not work in C shell, see
https://www.grymoire.com/Unix/Csh.html#uh-21
#!/bin/csh
set a = `./unit3.2a.sh 2 2`
echo $a
echo "The result is: $a"
echo "Storing the results.............."
echo "Storing the result: $a" >> unit3.txt
echo "The script is over"
that produces:
$ ./unit3.sh
4
The result is: 4
Storing the results..............
The script is over
Upvotes: 2