How to pass a variable in a command in UNIX? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” question(Shell Script) Variable not pass correctly when fetching value from file?Func name as variable in loopDynamically extract comments from files using catPass Shell variable to awkUsing sed to Replace Environment Variable with directory pathCreate variable based on the order a file is in an alphabetical list of filesWay to automatically replace original file with output?How to cut part of a “curl” answerHow do I pass a variable into an FTP connection?How to prevent parameter expansion around a variable I want to be resolved?
What is a non-alternating simple group with big order, but relatively few conjugacy classes?
Why are Kinder Surprise Eggs illegal in the USA?
The logistics of corpse disposal
What causes the vertical darker bands in my photo?
How to deal with a team lead who never gives me credit?
Identify plant with long narrow paired leaves and reddish stems
What's the purpose of writing one's academic biography in the third person?
Sci-Fi book where patients in a coma ward all live in a subconscious world linked together
Output the ŋarâþ crîþ alphabet song without using (m)any letters
How to tell that you are a giant?
How discoverable are IPv6 addresses and AAAA names by potential attackers?
How widely used is the term Treppenwitz? Is it something that most Germans know?
What to do with chalk when deepwater soloing?
How to react to hostile behavior from a senior developer?
Using audio cues to encourage good posture
English words in a non-english sci-fi novel
What does the "x" in "x86" represent?
What does this icon in iOS Stardew Valley mean?
When do you get frequent flier miles - when you buy, or when you fly?
Is there a (better) way to access $wpdb results?
Coloring maths inside a tcolorbox
Single word antonym of "flightless"
prime numbers and expressing non-prime numbers
What is the meaning of the new sigil in Game of Thrones Season 8 intro?
How to pass a variable in a command in UNIX?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” question(Shell Script) Variable not pass correctly when fetching value from file?Func name as variable in loopDynamically extract comments from files using catPass Shell variable to awkUsing sed to Replace Environment Variable with directory pathCreate variable based on the order a file is in an alphabetical list of filesWay to automatically replace original file with output?How to cut part of a “curl” answerHow do I pass a variable into an FTP connection?How to prevent parameter expansion around a variable I want to be resolved?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am a completely new user to UNIX shell programming. I want to know how I can pass a variable that is now a comment to another comment which is for getting a file from a website. For example:
I have made this variable as a command:
password1=$(.....)
and my new command is like this:
wget "http://.........?something&thecommandiscontinues"
I want to replace the word something with the output from my password1 command, so that I do not have to write a new script and manually enter it myself.
Please help me with writing simply and giving me solution. I have been working on this problem several weeks, but not resolved yet. Thank you.
shell variable
|
show 2 more comments
I am a completely new user to UNIX shell programming. I want to know how I can pass a variable that is now a comment to another comment which is for getting a file from a website. For example:
I have made this variable as a command:
password1=$(.....)
and my new command is like this:
wget "http://.........?something&thecommandiscontinues"
I want to replace the word something with the output from my password1 command, so that I do not have to write a new script and manually enter it myself.
Please help me with writing simply and giving me solution. I have been working on this problem several weeks, but not resolved yet. Thank you.
shell variable
1
Are you sure it's not something likehttp://...?password=something&...
wheresomething
is meant to be URI-encoded?
– Stéphane Chazelas
Mar 14 '17 at 16:46
1
Try(set -x; curl -GO --data-urlencode "=$password1" -d thecommandiscontinues http://........
)
– Stéphane Chazelas
Mar 14 '17 at 16:50
No,set -x
is so you can have a visual feedback of what command is being run. You need to replace.....
with the host name and path of the file (something likehost.example.com/path/to/file
without the trailing?
)thecommandiscontinues
is the text after the&
you have in your question! Add a-v
option tocurl
to see what HTTP request is being made. And if that doesn't work, please tell in what way it doesn't work.
– Stéphane Chazelas
Mar 14 '17 at 16:59
$password1
contains spaces characters. If you had doneprintf '"%s"n' "$password1"
, you would have seen them. You probably need to change the command that retrieves the password.
– Stéphane Chazelas
Mar 14 '17 at 17:20
Add anothers/^ *//;s/ *$//
to your sed command to remove leading an trailing space characters. Now what if the password contains space characters? It's common to have spaces in passwords.
– Stéphane Chazelas
Mar 14 '17 at 17:26
|
show 2 more comments
I am a completely new user to UNIX shell programming. I want to know how I can pass a variable that is now a comment to another comment which is for getting a file from a website. For example:
I have made this variable as a command:
password1=$(.....)
and my new command is like this:
wget "http://.........?something&thecommandiscontinues"
I want to replace the word something with the output from my password1 command, so that I do not have to write a new script and manually enter it myself.
Please help me with writing simply and giving me solution. I have been working on this problem several weeks, but not resolved yet. Thank you.
shell variable
I am a completely new user to UNIX shell programming. I want to know how I can pass a variable that is now a comment to another comment which is for getting a file from a website. For example:
I have made this variable as a command:
password1=$(.....)
and my new command is like this:
wget "http://.........?something&thecommandiscontinues"
I want to replace the word something with the output from my password1 command, so that I do not have to write a new script and manually enter it myself.
Please help me with writing simply and giving me solution. I have been working on this problem several weeks, but not resolved yet. Thank you.
shell variable
shell variable
edited Mar 14 '17 at 16:10
ilkkachu
63.5k10104181
63.5k10104181
asked Mar 14 '17 at 16:00
readerreader
155
155
1
Are you sure it's not something likehttp://...?password=something&...
wheresomething
is meant to be URI-encoded?
– Stéphane Chazelas
Mar 14 '17 at 16:46
1
Try(set -x; curl -GO --data-urlencode "=$password1" -d thecommandiscontinues http://........
)
– Stéphane Chazelas
Mar 14 '17 at 16:50
No,set -x
is so you can have a visual feedback of what command is being run. You need to replace.....
with the host name and path of the file (something likehost.example.com/path/to/file
without the trailing?
)thecommandiscontinues
is the text after the&
you have in your question! Add a-v
option tocurl
to see what HTTP request is being made. And if that doesn't work, please tell in what way it doesn't work.
– Stéphane Chazelas
Mar 14 '17 at 16:59
$password1
contains spaces characters. If you had doneprintf '"%s"n' "$password1"
, you would have seen them. You probably need to change the command that retrieves the password.
– Stéphane Chazelas
Mar 14 '17 at 17:20
Add anothers/^ *//;s/ *$//
to your sed command to remove leading an trailing space characters. Now what if the password contains space characters? It's common to have spaces in passwords.
– Stéphane Chazelas
Mar 14 '17 at 17:26
|
show 2 more comments
1
Are you sure it's not something likehttp://...?password=something&...
wheresomething
is meant to be URI-encoded?
– Stéphane Chazelas
Mar 14 '17 at 16:46
1
Try(set -x; curl -GO --data-urlencode "=$password1" -d thecommandiscontinues http://........
)
– Stéphane Chazelas
Mar 14 '17 at 16:50
No,set -x
is so you can have a visual feedback of what command is being run. You need to replace.....
with the host name and path of the file (something likehost.example.com/path/to/file
without the trailing?
)thecommandiscontinues
is the text after the&
you have in your question! Add a-v
option tocurl
to see what HTTP request is being made. And if that doesn't work, please tell in what way it doesn't work.
– Stéphane Chazelas
Mar 14 '17 at 16:59
$password1
contains spaces characters. If you had doneprintf '"%s"n' "$password1"
, you would have seen them. You probably need to change the command that retrieves the password.
– Stéphane Chazelas
Mar 14 '17 at 17:20
Add anothers/^ *//;s/ *$//
to your sed command to remove leading an trailing space characters. Now what if the password contains space characters? It's common to have spaces in passwords.
– Stéphane Chazelas
Mar 14 '17 at 17:26
1
1
Are you sure it's not something like
http://...?password=something&...
where something
is meant to be URI-encoded?– Stéphane Chazelas
Mar 14 '17 at 16:46
Are you sure it's not something like
http://...?password=something&...
where something
is meant to be URI-encoded?– Stéphane Chazelas
Mar 14 '17 at 16:46
1
1
Try
(set -x; curl -GO --data-urlencode "=$password1" -d thecommandiscontinues http://........
)– Stéphane Chazelas
Mar 14 '17 at 16:50
Try
(set -x; curl -GO --data-urlencode "=$password1" -d thecommandiscontinues http://........
)– Stéphane Chazelas
Mar 14 '17 at 16:50
No,
set -x
is so you can have a visual feedback of what command is being run. You need to replace .....
with the host name and path of the file (something like host.example.com/path/to/file
without the trailing ?
) thecommandiscontinues
is the text after the &
you have in your question! Add a -v
option to curl
to see what HTTP request is being made. And if that doesn't work, please tell in what way it doesn't work.– Stéphane Chazelas
Mar 14 '17 at 16:59
No,
set -x
is so you can have a visual feedback of what command is being run. You need to replace .....
with the host name and path of the file (something like host.example.com/path/to/file
without the trailing ?
) thecommandiscontinues
is the text after the &
you have in your question! Add a -v
option to curl
to see what HTTP request is being made. And if that doesn't work, please tell in what way it doesn't work.– Stéphane Chazelas
Mar 14 '17 at 16:59
$password1
contains spaces characters. If you had done printf '"%s"n' "$password1"
, you would have seen them. You probably need to change the command that retrieves the password.– Stéphane Chazelas
Mar 14 '17 at 17:20
$password1
contains spaces characters. If you had done printf '"%s"n' "$password1"
, you would have seen them. You probably need to change the command that retrieves the password.– Stéphane Chazelas
Mar 14 '17 at 17:20
Add another
s/^ *//;s/ *$//
to your sed command to remove leading an trailing space characters. Now what if the password contains space characters? It's common to have spaces in passwords.– Stéphane Chazelas
Mar 14 '17 at 17:26
Add another
s/^ *//;s/ *$//
to your sed command to remove leading an trailing space characters. Now what if the password contains space characters? It's common to have spaces in passwords.– Stéphane Chazelas
Mar 14 '17 at 17:26
|
show 2 more comments
2 Answers
2
active
oldest
votes
Replace something
with $password1
3
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL It does not make sense not to work. Also check your variable defininition . Trypassword="mypass"
- remove$( )
– George Vasiliou
Mar 14 '17 at 21:35
add a comment |
So if i did get it right you want to add what is in the variable password1 to the input of the command wget?
If this is the case try creating a fuction like this:
myFunction ()
wget -arg "something[...]$password1"
You can call this function in your code using this:
myVariable=$(myFunction);
You will get the output of your command in that variable.
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f351425%2fhow-to-pass-a-variable-in-a-command-in-unix%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Replace something
with $password1
3
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL It does not make sense not to work. Also check your variable defininition . Trypassword="mypass"
- remove$( )
– George Vasiliou
Mar 14 '17 at 21:35
add a comment |
Replace something
with $password1
3
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL It does not make sense not to work. Also check your variable defininition . Trypassword="mypass"
- remove$( )
– George Vasiliou
Mar 14 '17 at 21:35
add a comment |
Replace something
with $password1
Replace something
with $password1
edited Mar 14 '17 at 18:52
Michael Mrozek♦
62.5k29194214
62.5k29194214
answered Mar 14 '17 at 16:40
Tom ReingoldTom Reingold
311
311
3
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL It does not make sense not to work. Also check your variable defininition . Trypassword="mypass"
- remove$( )
– George Vasiliou
Mar 14 '17 at 21:35
add a comment |
3
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL It does not make sense not to work. Also check your variable defininition . Trypassword="mypass"
- remove$( )
– George Vasiliou
Mar 14 '17 at 21:35
3
3
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL, in what way does it not work?
– Stéphane Chazelas
Mar 14 '17 at 16:45
@JIGIL It does not make sense not to work. Also check your variable defininition . Try
password="mypass"
- remove $( )
– George Vasiliou
Mar 14 '17 at 21:35
@JIGIL It does not make sense not to work. Also check your variable defininition . Try
password="mypass"
- remove $( )
– George Vasiliou
Mar 14 '17 at 21:35
add a comment |
So if i did get it right you want to add what is in the variable password1 to the input of the command wget?
If this is the case try creating a fuction like this:
myFunction ()
wget -arg "something[...]$password1"
You can call this function in your code using this:
myVariable=$(myFunction);
You will get the output of your command in that variable.
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
add a comment |
So if i did get it right you want to add what is in the variable password1 to the input of the command wget?
If this is the case try creating a fuction like this:
myFunction ()
wget -arg "something[...]$password1"
You can call this function in your code using this:
myVariable=$(myFunction);
You will get the output of your command in that variable.
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
add a comment |
So if i did get it right you want to add what is in the variable password1 to the input of the command wget?
If this is the case try creating a fuction like this:
myFunction ()
wget -arg "something[...]$password1"
You can call this function in your code using this:
myVariable=$(myFunction);
You will get the output of your command in that variable.
So if i did get it right you want to add what is in the variable password1 to the input of the command wget?
If this is the case try creating a fuction like this:
myFunction ()
wget -arg "something[...]$password1"
You can call this function in your code using this:
myVariable=$(myFunction);
You will get the output of your command in that variable.
edited 9 hours ago
Rui F Ribeiro
42.1k1484142
42.1k1484142
answered Mar 14 '17 at 16:04
KingofkechKingofkech
4881620
4881620
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
add a comment |
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
Should I write anything in the brackets after myFunction?
– reader
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
I edited my post so i specify how to call the function:You can call this function in your code using this: myVariable=$(myFunction); You will get the output of your command in that variable.
– Kingofkech
Mar 14 '17 at 16:08
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f351425%2fhow-to-pass-a-variable-in-a-command-in-unix%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
-shell, variable
1
Are you sure it's not something like
http://...?password=something&...
wheresomething
is meant to be URI-encoded?– Stéphane Chazelas
Mar 14 '17 at 16:46
1
Try
(set -x; curl -GO --data-urlencode "=$password1" -d thecommandiscontinues http://........
)– Stéphane Chazelas
Mar 14 '17 at 16:50
No,
set -x
is so you can have a visual feedback of what command is being run. You need to replace.....
with the host name and path of the file (something likehost.example.com/path/to/file
without the trailing?
)thecommandiscontinues
is the text after the&
you have in your question! Add a-v
option tocurl
to see what HTTP request is being made. And if that doesn't work, please tell in what way it doesn't work.– Stéphane Chazelas
Mar 14 '17 at 16:59
$password1
contains spaces characters. If you had doneprintf '"%s"n' "$password1"
, you would have seen them. You probably need to change the command that retrieves the password.– Stéphane Chazelas
Mar 14 '17 at 17:20
Add another
s/^ *//;s/ *$//
to your sed command to remove leading an trailing space characters. Now what if the password contains space characters? It's common to have spaces in passwords.– Stéphane Chazelas
Mar 14 '17 at 17:26