Linked Questions

3
votes
3answers
4k 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 ...
0
votes
1answer
602 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?
1
vote
1answer
465 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: ...
2
votes
2answers
458 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 ...
-2
votes
1answer
230 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, ...
3
votes
1answer
124 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 ...
0
votes
2answers
99 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, ...
-2
votes
1answer
66 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
0answers
35 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 ...
8
votes
5answers
2k views

$ find -exec cd => gives error: => find: ‘cd’: No such file or directory

When I run this command it works: $ find . -inum 888696 -exec ls '{}' \; Conversation.pst Outlook Data File Outlook Data File.sbd Trash Unsent Messages Inbox.pst Outlook Data File.msf ...
3
votes
5answers
8k views

Perl script, do cd on terminal

In Script to change current directory (cd, pwd) it is shown how to run a bash script that changes terminal directory. But how do i run a perl script that runs a bash script that changes terminal ...
5
votes
2answers
1k views

Symbolic link to change directory only works from home dir

Using this answer, I have created a symbolic link in my .bashrc file to make changing to a frequently used directory easier. E.g. ln -s ~/a/b/c/d/development dev I can change directory from my home ...
-2
votes
1answer
1k views

Not able to cd into folder in Linux machine. Says file/folder does not exist

I have written a test ksh file to cd into a folder and do a listing. Following is written: `cd "their_file/"`; `pwd`; `ls -l`; Gives me following output: ./test.ksh: line 2: /home/user/final: Is ...
1
vote
3answers
682 views

one simple little “cd” doesn't work in script [duplicate]

#!/bin/bash # echo $PWD cd /home/<my username>/<long path> echo $PWD What I get when executing it with bash script.sh: /home/<my username> : No such file or directorye/<my ...
1
vote
2answers
490 views

Bash script to replace two steps: cd ./some_dir, ls -al?

I'd like to write a bash scipt that would change to target directory and list the contents of new directory, all in one step. It would replace the two commands I constantly use consecutively: cd ./...