Compare two variables with a Shell script
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:
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?
Thanks!
shell scripting echo
add a comment |Â
up vote
1
down vote
favorite
I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:
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?
Thanks!
shell scripting echo
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:
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?
Thanks!
shell scripting echo
I am new to shell programming, please forgive any blunder. I've been unable to find an answer to this:
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?
Thanks!
shell scripting echo
edited Jun 11 at 9:36
asked Jun 6 at 11:52
Wizzardzz
83
83
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
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.
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
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.
add a comment |Â
up vote
1
down vote
accepted
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.
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
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.
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.
answered Jun 6 at 13:21
rusty shackleford
1,135115
1,135115
add a comment |Â
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
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.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
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.
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.
answered Jun 6 at 13:41
Hotsndot
212
212
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f448177%2fcompare-two-variables-with-a-shell-script%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password