script to remember dir and always cd to it instead of the root dirchanging current working dir with a scriptShell Script for going through a dir recursively and chmodding based on conditions of file typePerl script, do cd on terminalHow to change the working directory of invoking shell using a script?Is it possible to change the PS1 periodically by a script in the background?bash script not creating alias and not updating $PS1Symbolic link to change directory only works from home dirBash script to replace two steps: cd ./some_dir, ls -al?Script to validate home dirHow do I make a cd command take effect outside of the bash script subshell?
Minkowski space
What are the differences between the usage of 'it' and 'they'?
Fencing style for blades that can attack from a distance
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Writing rule stating superpower from different root cause is bad writing
Why are 150k or 200k jobs considered good when there are 300k+ births a month?
Can I ask the recruiters in my resume to put the reason why I am rejected?
Why dont electromagnetic waves interact with each other?
What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)
The use of multiple foreign keys on same column in SQL Server
How much RAM could one put in a typical 80386 setup?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
Why does Kotter return in Welcome Back Kotter?
Why can't I see bouncing of a switch on an oscilloscope?
What does "Puller Prush Person" mean?
How does strength of boric acid solution increase in presence of salicylic acid?
How does one intimidate enemies without having the capacity for violence?
How to find program name(s) of an installed package?
Approximately how much travel time was saved by the opening of the Suez Canal in 1869?
Adding span tags within wp_list_pages list items
LaTeX closing $ signs makes cursor jump
How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?
Test if tikzmark exists on same page
Is it legal for company to use my work email to pretend I still work there?
script to remember dir and always cd to it instead of the root dir
changing current working dir with a scriptShell Script for going through a dir recursively and chmodding based on conditions of file typePerl script, do cd on terminalHow to change the working directory of invoking shell using a script?Is it possible to change the PS1 periodically by a script in the background?bash script not creating alias and not updating $PS1Symbolic link to change directory only works from home dirBash script to replace two steps: cd ./some_dir, ls -al?Script to validate home dirHow do I make a cd command take effect outside of the bash script subshell?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ?
#!/bin/bash
setdir()
cd $1
# remember the directory we are changing to here so whenever we do cd we go back to this set dir
setdir "$1"
bash shell-script cd-command
add a comment |
How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ?
#!/bin/bash
setdir()
cd $1
# remember the directory we are changing to here so whenever we do cd we go back to this set dir
setdir "$1"
bash shell-script cd-command
add a comment |
How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ?
#!/bin/bash
setdir()
cd $1
# remember the directory we are changing to here so whenever we do cd we go back to this set dir
setdir "$1"
bash shell-script cd-command
How can write a script to change to a given directory but also remember it so that when you do cd it always changes to that directory ?
#!/bin/bash
setdir()
cd $1
# remember the directory we are changing to here so whenever we do cd we go back to this set dir
setdir "$1"
bash shell-script cd-command
bash shell-script cd-command
edited Nov 25 '13 at 23:53
Gilles
546k12911111624
546k12911111624
asked Nov 25 '13 at 21:29
nixgadgetsnixgadgets
1184
1184
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Something like the following should work:
setdir()
cd "$1"
export SETDIR_DEFAULT="$1"
my_cd()
cd "$1-$SETDIR_DEFAULT-$HOME"
Note that these are functions, not a separate script. You can't do that from a separate script, since it would not be able to affect the parent shell that calls it.
If you really want to override cd
(please, don't do that), replace cd
with builtin cd
.
add a comment |
I know it might be a bit late for the answer, but you might like the idea of CDPATH
vaiable. It allows cd
to refer to content of directories in this variable from anywhere. Here's an example:
$ mkdir -p test/1,2,3
$ cd test/
$ mkdir 1/a,b,c
$ export CDPATH=/tmp/test/1
$ ls
1 2 3
$ cd a
$ pwd
/tmp/test/1/a
$ cd ~
$ cd b
$ pwd
/tmp/test/1/b
More details from man
:
CDPATH A <colon>-separated list of pathnames
that refer to directories. The cd utility
shall use this list in its attempt to change
the directory, as described in the DESCRIPTION.
An empty string in place of a directory
pathname represents the current directory. If
CDPATH is not set, it shall be treated as if
it were an empty string.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f102567%2fscript-to-remember-dir-and-always-cd-to-it-instead-of-the-root-dir%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Something like the following should work:
setdir()
cd "$1"
export SETDIR_DEFAULT="$1"
my_cd()
cd "$1-$SETDIR_DEFAULT-$HOME"
Note that these are functions, not a separate script. You can't do that from a separate script, since it would not be able to affect the parent shell that calls it.
If you really want to override cd
(please, don't do that), replace cd
with builtin cd
.
add a comment |
Something like the following should work:
setdir()
cd "$1"
export SETDIR_DEFAULT="$1"
my_cd()
cd "$1-$SETDIR_DEFAULT-$HOME"
Note that these are functions, not a separate script. You can't do that from a separate script, since it would not be able to affect the parent shell that calls it.
If you really want to override cd
(please, don't do that), replace cd
with builtin cd
.
add a comment |
Something like the following should work:
setdir()
cd "$1"
export SETDIR_DEFAULT="$1"
my_cd()
cd "$1-$SETDIR_DEFAULT-$HOME"
Note that these are functions, not a separate script. You can't do that from a separate script, since it would not be able to affect the parent shell that calls it.
If you really want to override cd
(please, don't do that), replace cd
with builtin cd
.
Something like the following should work:
setdir()
cd "$1"
export SETDIR_DEFAULT="$1"
my_cd()
cd "$1-$SETDIR_DEFAULT-$HOME"
Note that these are functions, not a separate script. You can't do that from a separate script, since it would not be able to affect the parent shell that calls it.
If you really want to override cd
(please, don't do that), replace cd
with builtin cd
.
edited Nov 25 '13 at 23:54
Gilles
546k12911111624
546k12911111624
answered Nov 25 '13 at 21:55
Chris DownChris Down
81.6k15190204
81.6k15190204
add a comment |
add a comment |
I know it might be a bit late for the answer, but you might like the idea of CDPATH
vaiable. It allows cd
to refer to content of directories in this variable from anywhere. Here's an example:
$ mkdir -p test/1,2,3
$ cd test/
$ mkdir 1/a,b,c
$ export CDPATH=/tmp/test/1
$ ls
1 2 3
$ cd a
$ pwd
/tmp/test/1/a
$ cd ~
$ cd b
$ pwd
/tmp/test/1/b
More details from man
:
CDPATH A <colon>-separated list of pathnames
that refer to directories. The cd utility
shall use this list in its attempt to change
the directory, as described in the DESCRIPTION.
An empty string in place of a directory
pathname represents the current directory. If
CDPATH is not set, it shall be treated as if
it were an empty string.
add a comment |
I know it might be a bit late for the answer, but you might like the idea of CDPATH
vaiable. It allows cd
to refer to content of directories in this variable from anywhere. Here's an example:
$ mkdir -p test/1,2,3
$ cd test/
$ mkdir 1/a,b,c
$ export CDPATH=/tmp/test/1
$ ls
1 2 3
$ cd a
$ pwd
/tmp/test/1/a
$ cd ~
$ cd b
$ pwd
/tmp/test/1/b
More details from man
:
CDPATH A <colon>-separated list of pathnames
that refer to directories. The cd utility
shall use this list in its attempt to change
the directory, as described in the DESCRIPTION.
An empty string in place of a directory
pathname represents the current directory. If
CDPATH is not set, it shall be treated as if
it were an empty string.
add a comment |
I know it might be a bit late for the answer, but you might like the idea of CDPATH
vaiable. It allows cd
to refer to content of directories in this variable from anywhere. Here's an example:
$ mkdir -p test/1,2,3
$ cd test/
$ mkdir 1/a,b,c
$ export CDPATH=/tmp/test/1
$ ls
1 2 3
$ cd a
$ pwd
/tmp/test/1/a
$ cd ~
$ cd b
$ pwd
/tmp/test/1/b
More details from man
:
CDPATH A <colon>-separated list of pathnames
that refer to directories. The cd utility
shall use this list in its attempt to change
the directory, as described in the DESCRIPTION.
An empty string in place of a directory
pathname represents the current directory. If
CDPATH is not set, it shall be treated as if
it were an empty string.
I know it might be a bit late for the answer, but you might like the idea of CDPATH
vaiable. It allows cd
to refer to content of directories in this variable from anywhere. Here's an example:
$ mkdir -p test/1,2,3
$ cd test/
$ mkdir 1/a,b,c
$ export CDPATH=/tmp/test/1
$ ls
1 2 3
$ cd a
$ pwd
/tmp/test/1/a
$ cd ~
$ cd b
$ pwd
/tmp/test/1/b
More details from man
:
CDPATH A <colon>-separated list of pathnames
that refer to directories. The cd utility
shall use this list in its attempt to change
the directory, as described in the DESCRIPTION.
An empty string in place of a directory
pathname represents the current directory. If
CDPATH is not set, it shall be treated as if
it were an empty string.
answered 2 days ago
rushrush
19.5k46596
19.5k46596
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f102567%2fscript-to-remember-dir-and-always-cd-to-it-instead-of-the-root-dir%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown