-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 ='$*'
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
Ahmad
  • 1
  • 1
  • 1
  • Whats the argument ? And whats the rest of the script? – 123 Jan 28 '16 at 11:33
  • A string with spaces – Ahmad Jan 28 '16 at 11:52
  • Put an example in your question. – 123 Jan 28 '16 at 11:54
  • Why there is a space between the variable and the assignment operator (`=`)? You need some basics first. Try [this](http://www.grymoire.com/Unix/Sh.html), it talks about some of the basics of the basics. – Jahid Jan 28 '16 at 12:33
  • http://unix.stackexchange.com/questions/32290/pass-command-line-arguments-to-bash-script would be a good duplicate but it was migrated. – tripleee Jan 28 '16 at 13:37

1 Answers1

1

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

str1="$@"
Chris Maes
  • 35,025
  • 12
  • 111
  • 136
  • 1
    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. – tripleee Jan 28 '16 at 11:47
  • 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 – Ahmad Jan 28 '16 at 11:48
  • 1
    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... – Chris Maes Jan 28 '16 at 11:52
  • 1
    See http://stackoverflow.com/questions/12711786/bash-convert-command-line-arguments-into-array – tripleee Jan 28 '16 at 13:38