How do I cd and then ls in my cshrc
Clash Royale CLAN TAG#URR8PPP
I want to be able to cd into a path and have it ls
automatically.
I have tried doing a function such as
cs() cd "@a" ; ls
but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried
alias cs ' cd !:1 ; ls '
I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.
linux ls cd-command csh
add a comment |
I want to be able to cd into a path and have it ls
automatically.
I have tried doing a function such as
cs() cd "@a" ; ls
but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried
alias cs ' cd !:1 ; ls '
I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.
linux ls cd-command csh
See alsoalias cwdcmd ls
(assuming your csh is actually tcsh)
– Stéphane Chazelas
Dec 11 at 22:01
add a comment |
I want to be able to cd into a path and have it ls
automatically.
I have tried doing a function such as
cs() cd "@a" ; ls
but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried
alias cs ' cd !:1 ; ls '
I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.
linux ls cd-command csh
I want to be able to cd into a path and have it ls
automatically.
I have tried doing a function such as
cs() cd "@a" ; ls
but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried
alias cs ' cd !:1 ; ls '
I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.
linux ls cd-command csh
linux ls cd-command csh
edited Dec 11 at 21:20
Jeff Schaller
38.4k1053125
38.4k1053125
asked Dec 11 at 18:40
Makuza
82
82
See alsoalias cwdcmd ls
(assuming your csh is actually tcsh)
– Stéphane Chazelas
Dec 11 at 22:01
add a comment |
See alsoalias cwdcmd ls
(assuming your csh is actually tcsh)
– Stéphane Chazelas
Dec 11 at 22:01
See also
alias cwdcmd ls
(assuming your csh is actually tcsh)– Stéphane Chazelas
Dec 11 at 22:01
See also
alias cwdcmd ls
(assuming your csh is actually tcsh)– Stéphane Chazelas
Dec 11 at 22:01
add a comment |
1 Answer
1
active
oldest
votes
You were very very close.
Unix loves backslashes; Unix eats backslashes for breakfast.
You need
alias cs 'cd !:1; ls'
If you look at the documentation for csh (and its descendants),
you'll see that !
refers to the history mechanism,
which lets you refer to previous command(s).
The simplest example is !!
,
which recalls and repeats the most recent command. !:1
means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
, !:0
is grep
and !:1
is needle
).
Bash and other descendants of the Bourne shell have a feature
that is very similar.
C shell aliases are a little weird.
When you run an alias, the command that you typed
(e.g., cs vacation_photographs
) is treated as the "previous command".
So, when the alias runs, !:1
is replaced with vacation_photographs
.
The catch is that this happens when the alias runs.
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc
says
set prompt = '% '
alias cs 'cd !:1; ls'
then !:1
is evaluated as prompt
,
and the alias is defined as cd prompt; ls
.
To be able to refer to the command that you typed
(vacation_photographs
),
you need to define the alias to be cd !:1; ls
,
and so you need to use the backslash
to defer the interpretation of the !:1
,
so it will be evaluated when the alias is run
instead of when it is defined.
If you've been doing
alias cs 'cd !:1; ls'
and it doesn't do anything (not even give you an error message),
I cannot explain that.
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
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%2f487420%2fhow-do-i-cd-and-then-ls-in-my-cshrc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You were very very close.
Unix loves backslashes; Unix eats backslashes for breakfast.
You need
alias cs 'cd !:1; ls'
If you look at the documentation for csh (and its descendants),
you'll see that !
refers to the history mechanism,
which lets you refer to previous command(s).
The simplest example is !!
,
which recalls and repeats the most recent command. !:1
means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
, !:0
is grep
and !:1
is needle
).
Bash and other descendants of the Bourne shell have a feature
that is very similar.
C shell aliases are a little weird.
When you run an alias, the command that you typed
(e.g., cs vacation_photographs
) is treated as the "previous command".
So, when the alias runs, !:1
is replaced with vacation_photographs
.
The catch is that this happens when the alias runs.
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc
says
set prompt = '% '
alias cs 'cd !:1; ls'
then !:1
is evaluated as prompt
,
and the alias is defined as cd prompt; ls
.
To be able to refer to the command that you typed
(vacation_photographs
),
you need to define the alias to be cd !:1; ls
,
and so you need to use the backslash
to defer the interpretation of the !:1
,
so it will be evaluated when the alias is run
instead of when it is defined.
If you've been doing
alias cs 'cd !:1; ls'
and it doesn't do anything (not even give you an error message),
I cannot explain that.
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
add a comment |
You were very very close.
Unix loves backslashes; Unix eats backslashes for breakfast.
You need
alias cs 'cd !:1; ls'
If you look at the documentation for csh (and its descendants),
you'll see that !
refers to the history mechanism,
which lets you refer to previous command(s).
The simplest example is !!
,
which recalls and repeats the most recent command. !:1
means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
, !:0
is grep
and !:1
is needle
).
Bash and other descendants of the Bourne shell have a feature
that is very similar.
C shell aliases are a little weird.
When you run an alias, the command that you typed
(e.g., cs vacation_photographs
) is treated as the "previous command".
So, when the alias runs, !:1
is replaced with vacation_photographs
.
The catch is that this happens when the alias runs.
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc
says
set prompt = '% '
alias cs 'cd !:1; ls'
then !:1
is evaluated as prompt
,
and the alias is defined as cd prompt; ls
.
To be able to refer to the command that you typed
(vacation_photographs
),
you need to define the alias to be cd !:1; ls
,
and so you need to use the backslash
to defer the interpretation of the !:1
,
so it will be evaluated when the alias is run
instead of when it is defined.
If you've been doing
alias cs 'cd !:1; ls'
and it doesn't do anything (not even give you an error message),
I cannot explain that.
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
add a comment |
You were very very close.
Unix loves backslashes; Unix eats backslashes for breakfast.
You need
alias cs 'cd !:1; ls'
If you look at the documentation for csh (and its descendants),
you'll see that !
refers to the history mechanism,
which lets you refer to previous command(s).
The simplest example is !!
,
which recalls and repeats the most recent command. !:1
means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
, !:0
is grep
and !:1
is needle
).
Bash and other descendants of the Bourne shell have a feature
that is very similar.
C shell aliases are a little weird.
When you run an alias, the command that you typed
(e.g., cs vacation_photographs
) is treated as the "previous command".
So, when the alias runs, !:1
is replaced with vacation_photographs
.
The catch is that this happens when the alias runs.
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc
says
set prompt = '% '
alias cs 'cd !:1; ls'
then !:1
is evaluated as prompt
,
and the alias is defined as cd prompt; ls
.
To be able to refer to the command that you typed
(vacation_photographs
),
you need to define the alias to be cd !:1; ls
,
and so you need to use the backslash
to defer the interpretation of the !:1
,
so it will be evaluated when the alias is run
instead of when it is defined.
If you've been doing
alias cs 'cd !:1; ls'
and it doesn't do anything (not even give you an error message),
I cannot explain that.
You were very very close.
Unix loves backslashes; Unix eats backslashes for breakfast.
You need
alias cs 'cd !:1; ls'
If you look at the documentation for csh (and its descendants),
you'll see that !
refers to the history mechanism,
which lets you refer to previous command(s).
The simplest example is !!
,
which recalls and repeats the most recent command. !:1
means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
, !:0
is grep
and !:1
is needle
).
Bash and other descendants of the Bourne shell have a feature
that is very similar.
C shell aliases are a little weird.
When you run an alias, the command that you typed
(e.g., cs vacation_photographs
) is treated as the "previous command".
So, when the alias runs, !:1
is replaced with vacation_photographs
.
The catch is that this happens when the alias runs.
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc
says
set prompt = '% '
alias cs 'cd !:1; ls'
then !:1
is evaluated as prompt
,
and the alias is defined as cd prompt; ls
.
To be able to refer to the command that you typed
(vacation_photographs
),
you need to define the alias to be cd !:1; ls
,
and so you need to use the backslash
to defer the interpretation of the !:1
,
so it will be evaluated when the alias is run
instead of when it is defined.
If you've been doing
alias cs 'cd !:1; ls'
and it doesn't do anything (not even give you an error message),
I cannot explain that.
edited Dec 11 at 21:12
answered Dec 11 at 18:57
G-Man
12.9k93264
12.9k93264
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
add a comment |
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
Dec 11 at 20:19
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
Dec 11 at 21:58
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f487420%2fhow-do-i-cd-and-then-ls-in-my-cshrc%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
See also
alias cwdcmd ls
(assuming your csh is actually tcsh)– Stéphane Chazelas
Dec 11 at 22:01