Linked Questions
25 questions linked to/from Script to change current directory (cd, pwd)
3
votes
3
answers
6k
views
cd works in shell but not in script [duplicate]
I frequently have to cd from $HOME to a particular long directory path. So I thought I'd put a cdscript in $HOME to make getting there a little quicker.
cdscript:
#!/bin/sh
directory="/some/big/long ...
2
votes
2
answers
7k
views
Changing current directory with a bash script? [duplicate]
I was wondering if it's possible to change directory of a shell from a bash script, but keep the directory change persistent to more than just the subshell.
I'm aware that when you run cd inside a ...
0
votes
2
answers
1k
views
How do I make a cd command take effect outside of the bash script subshell? [duplicate]
I made this script:
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "only use one argument"
exit 1
fi
mkdir $1
sleep 0.5
cd $1
exit 0
I wanted to make a script that I would later put into /usr/bin, ...
0
votes
1
answer
2k
views
changing current directory from child process [duplicate]
How would you arrange for a shell script to be executed in a child process, while still being able to change the current directory of the invoking shell?
-2
votes
1
answer
2k
views
CD $Variable not working when used in a (Bash) Shell Script [duplicate]
File name: Test.sh
#!/bin/bash
ZDir="$(echo /usr/src)"
cd "$ZDir"
When I execute the script ./Test.sh, the command cd doesn't do anything.
If I try to do it directly in the bash terminal, it works ...
0
votes
1
answer
1k
views
Bash script did not change the directory as written [duplicate]
Here is my script to change the directory
[user@linux ~]$ cat script.sh
echo Before: $(pwd)
cd "$1"
echo After : $(pwd)
[user@linux ~]$
When I tested it, it did not really change the directory as ...
1
vote
1
answer
1k
views
Run cd with path variable in bash script not working [duplicate]
When i run the script:
#!/bin/bash
DRUPAL_ROOT=$(drush status root --format=list)
if [ -z $DRUPAL_ROOT ]
then
echo -e "Not exists Drupal core"
else
echo $DRUPAL_ROOT
cd $DRUPAL_ROOT
fi
Output:
...
3
votes
1
answer
476
views
Why can't I use cd in a bash script? [duplicate]
I made a very simple script
#!/bin/bash
mkdir $1 && cd $1
when I execute
myscript test
It creates test directory but doesn't go inside just after. I don't understand why, on my fedora 27 ...
-2
votes
1
answer
299
views
How can I get a shell script to change directory for me? [duplicate]
here is a small test I ran, to try and move me back to root:
#!/bin/bash
pwd
cd /
pwd
It returns the current working directory, and then the correct new one, but when the script finished executing, I ...
0
votes
1
answer
521
views
cd does not take variable as argument in bash script [duplicate]
I'm trying to make a bash script that will give me a command that will take a number n as argument and change the directory to the nth directory listed by running ls in the working directory. Here's ...
0
votes
0
answers
44
views
Script that uses new directory [duplicate]
I have a script that I need to run an application which, at the end, changes the working directory. (I'm modifying an ".sh" script and am new to Unix.) I then need to run some commands in that new ...
0
votes
1
answer
41
views
change directory in shell script based on prompt [duplicate]
I'm currently at /opt and running a small shell script. My "no" condition works perfectly, however, my yes condition doesn't work, I 'am still at /opt.
while true; do
read -p "go to log location ?...
0
votes
0
answers
19
views
how to move working directory prompt inside of script [duplicate]
forgive me, the title was hard to come up with as i'm not even sure how to ask this any other way. i have a script that moves it's contents and then nukes the remains. here's the script (works just ...
0
votes
0
answers
16
views
Why doesn't the directory stack persist from inside a script? [duplicate]
I was working on a script to set up a project-specific environment. I created a script to set up the directory stack as suggested in the first comment to this question. Console output provided ...