Create Directory

Hi All,

I am new to Shell scripting. I have two arguments $from and $to. My requirement is

$dpdir= DB_FROM_$from_TO_$to
mkdir $dpdir

Please help me on this.

Thanks,
Mani

pvmanikandan,

What are the values of $from and $to?

Are you trying to create a range of directories?

Also, some adjustments are in order in the variable assignment statement. You should consider using curly braces around the variable names so that the other characters are not interpreted as part of the variable name.

e.g.

dpdir=DB_FROM_${from}_TO_${to}
1 Like

Hi,

Thanks for the reply.

I tried that its giving error

./datapump.sh: line 57: =DP_FROM_{ad}_TO_{af}: command not found

In addition to the braces ({ and }) - and you didn't do exactly as mjf suggested (you missed the $'s), you should remove spaces from either side of the assignment:

# good
var=value

# bad
var =value
var= value

If that does not solve the problem, please post line "57" (using code tags, please)

Hi Scott,

I am in writing code of database refresh. So the code is incomplete and its in starting stage.

The code is

##############################################
read -p "Enter From Region: " from
echo "From Region is : $from"
if [ `echo $from` = `echo $from | tr [:upper:] [:lower:]` ];then
    froml=$(case_convert $from)
    echo "After Case Convert : $froml"
else
    froml=$from
    echo "After Case Convert : $froml"
fi

read -p "Enter To Region: " to
echo "To Region is : $to"
if [ `echo $to` = `echo $to | tr [:upper:] [:lower:]` ];then
        tol=$(case_convert $to)
        echo "After Case Convert : $tol"
else
        tol=$to
        echo "After Case Convert : $tol"
fi

read -p "Enter From TNS: " ftns
echo "From TNS is : $ftns"

read -p "Enter To TNS: " ttns
echo "To TNS is : $ttns"

read -p "Enter From Pwd: " fpwd
echo "From User Pwd is : $fpwd"

read -p "Enter To Pwd: " tpwd
echo "To User Pwd is : " $tpwd

read -p "Enter Apps Pwd: " $apwd
echo "Apps Pwd is : " $apwd

###############################################

###############################################
Create Directories and Sub-Directories
###############################################

$dpdir=DP_FROM_{$from}_TO_{$to}
mkdir $dpdir

I believe there is no space in the assignment.

Thanks

$dpdir=DP_FROM_{$from}_TO_{$to}

Should be:

dpdir=DP_FROM_${from}_TO_${to}

I would also add:

to=$(echo $to | tr '[a-z]' '[A-Z]')
from=$(echo $from | tr '[a-z]' '[A-Z]')

Then you won't need those if statements:

if [ `echo $from` = `echo $from | tr [:upper:] [:lower:]` ];then
...
1 Like

Ohhh I have not noticed that. But the directory created like this

DP_FROM_{AF}_TO_{AD}

This:

dpdir=DP_FROM_{$from}_TO_{$to}

would give that result.

But this:

dpdir=DP_FROM_${from}_TO_${to}

would not.

Hi Scott,

Thanks Scott...It worked.... Also thanks for the suggestion...I will change my code....

Thanks,
Mani

---------- Post updated at 07:09 PM ---------- Previous update was at 07:05 PM ----------

Actually mjf has already pointed that...but i have used it wrong....Thanks to mjf...