I believe that this does what you want. It will put all the arguments in one string, separated by spaces, with single quotes around all:
str="'$*'"
$*
produces all the scripts arguments separated by the first character of $IFS
which, by default, is a space.
Inside a double quoted string, there is no need to escape single-quotes.
Example
Let us put the above in a script file:
$ cat script.sh
#!/bin/sh
str="'$*'"
echo "$str"
Now, run the script with sample arguments:
$ sh script.sh one two three four 5
'one two three four 5'
This script is POSIX. It will work with bash
but it does not require bash
.
A variation: concatenating with slashes instead of spaces
We can change from spaces to another character by adjusting IFS
:
$ cat script.sh
#!/bin/sh
old="$IFS"
IFS='/'
str="'$*'"
echo "$str"
IFS=$old
For example:
$ sh script.sh one two three four
'one/two/three/four'
Just for completeness, you don't need all those (") nor the final $(echo ...)
.
Here's the simplified version of your assignments that produce the same
effect:
STARTIME=$(date +"%T")
ENDTIME="$STARTIME today + 10 seconds"
CALL="date -d '$ENDTIME' +'%H:%M:%S'"
Note how you don't need to quote when doing var=$(...) but you do usually
with var="many words":
a=$(echo 'a b'); echo "$a" # result: a b
Inside (") a (') has no special significance, and vice-versa, eg:
a="that's nice"; echo "$a" # result: that's nice
a='that "is nice'; echo "$a" # result: that "is nice
Best Answer
From
bash
manual:Thus: