create a directory at user home using shell script
I am trying for creating a "test" directory in user home using shell script as follows
mkdir -p ~/test But it creates ~/test directory at script executing path instead of creating "test" directory in user home . But when i run "mkdir -p ~/test" on terminal then it creates test directory successfully in user home . Please help me to create directory in user home. ThanQ, Nagendra |
try using $HOME instead of ~
|
What is $HOME set to when you have the problem?
|
You are using a shell that doesn't understand "~" like the old /bin/sh. Use ksh, bash or similar. AlucardZero workaround will work.
|
$HOME set to '/'
ThanQ, Nagendra |
Are you logged in as root ?
|
Quote:
Code:
grep '^root:' /etc/passwd | cut -d':' -f6 EDIT: what was "script executing path"? |
This " grep '^root:' /etc/passwd | cut -d':' -f6 " command gives "/" .This is smae as $HOME. Here I am logged in as root .
ThanQ, Nagendra |
OK, so you are logged in as root, root's home directory is / and $HOME is correctly set. We still don't know which shell root is using so please post the output of
Code:
grep '^root:' /etc/passwd | cut -d':' -f7 Quote:
Please post a copy-and-paste of doing that so we can see exactly what happened, along with "extras". Something like this. Code:
c@CW8:/tmp$ echo $HOME When your wrote "But when i run "mkdir -p ~/test" on terminal then it creates test directory successfully in user home", do you mean directory /test was created? |
Output of " grep '^root:' /etc/passwd | cut -d':' -f7" is /sbin/sh
Quote:
Quote:
Code:
Quote:
ThanQ, Nagendra |
Please clarify why do you want test to be created elsewhere than under / ?
What you show is correct and expected behavior. |
All times are GMT -5. The time now is 08:58 AM. |