how to insert $2 argument until the end to variable?
how to insert $2 argument until the end to variable?
For example: >> cucu.csh user "long long message " $1 = user $2 = "long long message " ? |
You might have to explain further?? You seemed to have asked the question and provided the answer.
|
What i'm trying to say is...
how can i set $2 to be the rest of the line. for now i have $2 = "long" |
Quote:
|
You don't have to SET anything. Your first parameter is $1, and your entire second parameter, so long as it's enclosed in quotes, is $2.
Here's a simple script called test.sh, to demonstrate this principle: Code:
echo The first variable passed is $1 Code:
:~> ./test.sh user "long, long, long, long message" |
O.K...
So if i force user to use " message " how can i check if it use commas for message? |
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. |
Another way you could go is like this:
Code:
LONGSTRING=$2 $3 $4 $5 $6 |
Quote:
Code:
test text Code:
test text |
Also if you really only want to have 2 and exactly 2 arguments:
Code:
if (( $# != 2 )) |
If your script expects two arguments, and you want to combine any extra arguments to the second one, use
Code:
first="$1" |
All times are GMT -5. The time now is 02:25 AM. |