how to insert $2 argument until the end to variable?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I assume you mean quotes, not commas. The answer is: it depends.
If you only expect two parameters, then the presence of a third parameter would indicate the user had failed to use quotes correctly. In that case, I'd add a test to see if $3 is non-blank, and echo an error message if true.
LONGSTRING=$2 $3 $4 $5 $6
echo The first variable passed is $1
echo The second variable passed is $LONGSTRING
This one assumes no more than five words are part of the long string. You could expand it to the max you expect, or construct a FOR loop. Either way, the user no longer has to worry about quotes.
This one assumes no more than five words are part of the long string. You could expand it to the max you expect, or construct a FOR loop. Either way, the user no longer has to worry about quotes.
The catch is that all whitespace will be converted into a single space. So if the user enters (without quotes) this:
Code:
test text
the script will see it like this:
Code:
test text
Whitespace will still be preserved if quotes are used.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.