(Sorry for the confusion. Previous $ sign occurred when I tried to simplify the actual problem. Thanks for correcting the question)
I wanted to split a directory name on underscores (ex: dir_to_split=”my_test_dir”) like this:
my_dir=($dir_to_split)
var=$(echo $my_dir | awk -F"_" '{print $1,$2,$3}')
set -- $var
splited_1=$1
splited_2=$2
splited_3=$3
now using these splited_x is causing me errors. ex.
myprograme $splited_1 $splited_2 $splited_3
Can anyone please help me with this ? Thank you….
(Rewritten after updated question.)
What kind of errors do you get? I find it useful to add
set -xto the top of my shell scripts when debugging, this lets the shell print all commands it executes so you can pinpoint the line where problems begin.Are you sure that
$dir_to_splitis actually set? Does it contain spaces or tabs? Does it contain two underscores? I don’t see any other problems right now.There are in-shell methods of splitting a variable such as:
See also this SO question.