Reputation: 13
I am trying to write a simple shell script where on running this script it should change to another directory. I want to make it by allocating a variable to the path. vi loc_change
#!/bin/bash
change= "/home/oracle/Public"
cd $change
echo "directory changed"
after doing this I have changed the permissions
chmod 777 loc_change
and executing this source ./loc_change
after executing this I am getting following error.
./loc_change: line 2: /home/oracle/Public: is a directory
directory changed
I have seen this type of decleration in tldp. I am very new to Shell scripting.
Upvotes: 0
Views: 227
Reputation: 17210
#!/bin/bash
change="/home/oracle/Public"
remove the space
try,
#!/bin/bash
change="/rooot"
cd $change > /dev/null > 2&>1
if [ $? -eq 0 ]
then
echo "Directory Changed"
else
echo "Directory Not changed"
fi
Upvotes: 1
Reputation: 485
There should be no space.
#!/bin/bash
change="/home/oracle/Public"
cd $change
echo "directory changed"
Upvotes: 0