The problem is i'm not getting a clean way to seperate the arguments with a single white space as seen in the "desired output:" above when the parameters are passed in single qoutes like below:
In single quotes you must not \escape the \escape:
./loopissue.sh '/tmp/scripts\n/tmp/mrt\n/tmp/exe'
The shell removes the 'single quotes' and the "double quotes" before it invokes the loopissue.sh. The quotes are only the hint to pass it as one string - to $1 in the loopissue.sh.
Also the following works (and is even better portable, because the \n must be interpreted by the echo command):
./loopissue.sh '/tmp/scripts
/tmp/mrt
/tmp/exe'
Is there a reason to squeeze all arguments into one $1 ?
Maybe you can simply use
./loopissue.sh /tmp/scripts /tmp/mrt /tmp/exe
This maps to $1 $2 $3 in the loopissue.sh
And it's simple to print them in different formats:
#!/bin/ksh
for dirpath
do
echo "DIRR_PATH:$dirpath"
done
echo "Desired Output:$@"
Note that for dirpath is short for for dirpath in "$@" . In other words, a for loop defaults to loop thru all arguments.
If parameter $1 contains literal \\n then you can use sed to convert to a space
VAR1=$(printf "%s\n" "$1" | sed 's/\\\\n/ /g')
The \ and \n are really special. Some explanations:
I used ' ' because the shell treats \ literally in them - in contrast to " " .
I used $( ) because the shell does not mistreat \ in them - in contrast to ` ` .
I used printf "%s\n" because the ksh builtin echo treats \n in a special way.
Of course I put the $1 in "quotes" to have variable substitution but no further expansions. Note that a literal \ in " " is special but not if it stems from a variable substitution.
So sed sees s/\\\\n/ /g , and treats each \\ as one \