-2

I am trying to assign the command line parameters to a variable (Entire argument to one variable) in shell script but it is not working Here is what I tried:

str1 ='$*'
str1 ="$*"
set str1 =$*
set str1 ="$*"
set str1 ='(echo $*)'
set str1 ='$*'
5
  • Whats the argument ? And whats the rest of the script? Commented Jan 28, 2016 at 11:33
  • A string with spaces Commented Jan 28, 2016 at 11:52
  • Put an example in your question. Commented Jan 28, 2016 at 11:54
  • Why there is a space between the variable and the assignment operator (=)? You need some basics first. Try this, it talks about some of the basics of the basics. Commented Jan 28, 2016 at 12:33
  • unix.stackexchange.com/questions/32290/… would be a good duplicate but it was migrated. Commented Jan 28, 2016 at 13:37

1 Answer 1

1

If you want to get one variable containig all arguments; use $@:

str1="$@"
Sign up to request clarification or add additional context in comments.

4 Comments

But note that this breaks the special semantics of "$@" - there is no way for an argument to contain a space, for example. In modern shells, use an array instead. This is a massive FAQ.
Hello Chris, I tried that as well but no luck. if I remove "set" it says command not found, without "set" I don't get error but nothing is assigned
do you put this in a script? How do you use this? What output do you get? What do you expect? There are many questions like this around...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.