1

I have a script that allows me to compare these variables:

FT_NBR1=\'?"\"'\
FT_NBR2=rcrdmddd

My question is how can I pass the FT_NBRs variables to the script to execute the comparison in the terminal?

1

You can export the variables using your shell, then they will be available in the script.

Example script:

#!/bin/bash --
echo "${test}"

Export variable and run script:

$ export test=something
$ ./script
something

The way you are trying to assign values to variables will not work.

FT_NBR1=\'?"\"'\
FT_NBR2=rcrdmddd

FT_NBR2 is fine, but FT_NBR1 is not valid. Have a look a single vs double quotes and special character escaping.

0
0

You can pass environmental variables to a script with setting the variables just before. The variables will not be set in the current environment, which can be useful in some cases.

script.sh:

#!/bin/bash
echo "var1: $var1"

and then call it with

$ var1=234 ./script.sh
var1: 123
$ echo "var1: $var1"
var1: 

This works in bash. I don't know about general POSIX compability.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.