[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Linux Shell Scripting: Passing String Values

Posted on 2013-11-08
3
Medium Priority
?
350 Views
Last Modified: 2013-11-08
How can I pass the value of x and y through the command path?

For example:

sh ./xyz.sh Hello World
#!/bin/sh
$x="Hello";
$y="World";
echo $x $y;

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
simon3270 earned 2000 total points
ID: 39633552
#!/bin/sh
$x="$1"
$y="$2"
echo $x $y

Open in new window

call it as, for example
   myscript.sh Hello World
0
 
LVL 20

Expert Comment

by:simon3270
ID: 39633561
Note that you can only have 9 parameters passed like this ($1 to $9).  If you try to refer to $10 in your script, it will use the value of $1 and append a zero to that value.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 39635101
To refer to parameters 10-255, you need to enclose them in braces, eg:

${10}
${11}
..
${255}

The only shell that doesn't support this is the tradition bourne shell.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
Utilizing an array to gracefully append to a list of EmailAddresses
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question