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;








1















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.










share|improve this question



















  • 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






  • 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 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











  • 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

















1















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.










share|improve this question



















  • 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






  • 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 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











  • 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













1












1








1


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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 like http://...?password=something&... where something 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 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











  • 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












  • 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






  • 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 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











  • 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







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










2 Answers
2






active

oldest

votes


















3














Replace something with $password1






share|improve this answer




















  • 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 . Try password="mypass" - remove $( )

    – George Vasiliou
    Mar 14 '17 at 21:35



















1














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.






share|improve this answer

























  • 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











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
);



);













draft saved

draft discarded


















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









3














Replace something with $password1






share|improve this answer




















  • 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 . Try password="mypass" - remove $( )

    – George Vasiliou
    Mar 14 '17 at 21:35
















3














Replace something with $password1






share|improve this answer




















  • 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 . Try password="mypass" - remove $( )

    – George Vasiliou
    Mar 14 '17 at 21:35














3












3








3







Replace something with $password1






share|improve this answer















Replace something with $password1







share|improve this answer














share|improve this answer



share|improve this answer








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 . Try password="mypass" - remove $( )

    – George Vasiliou
    Mar 14 '17 at 21:35













  • 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 . Try password="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














1














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.






share|improve this answer

























  • 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















1














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.






share|improve this answer

























  • 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













1












1








1







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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

Popular posts from this blog

Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

Frič See also Navigation menuinternal link

Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant