Error converting a bash function to a csh alias
I am writing a csh alias so that I can use the following bash function in my csh :
function up( )
{
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
P=$P/..
done
cd $P
export MPWD=$P
}
(I stole the above bash function from here)
I have written this:
alias up 'set LIMIT=$1; set P=$PWD; set counter = LIMIT; while[counter!=0] set counter = counter-1; P=$P/.. ; end cd $P; setenv MPWD=$P'
However, I am getting the following error:
while[counter!=0]: No match.
P=/net/devstorage/home/rghosh/..: Command not found.
end: Too many arguments.
and my script is not working as intended. I have been reading up on csh from here.
csh
add a comment |
I am writing a csh alias so that I can use the following bash function in my csh :
function up( )
{
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
P=$P/..
done
cd $P
export MPWD=$P
}
(I stole the above bash function from here)
I have written this:
alias up 'set LIMIT=$1; set P=$PWD; set counter = LIMIT; while[counter!=0] set counter = counter-1; P=$P/.. ; end cd $P; setenv MPWD=$P'
However, I am getting the following error:
while[counter!=0]: No match.
P=/net/devstorage/home/rghosh/..: Command not found.
end: Too many arguments.
and my script is not working as intended. I have been reading up on csh from here.
csh
add a comment |
I am writing a csh alias so that I can use the following bash function in my csh :
function up( )
{
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
P=$P/..
done
cd $P
export MPWD=$P
}
(I stole the above bash function from here)
I have written this:
alias up 'set LIMIT=$1; set P=$PWD; set counter = LIMIT; while[counter!=0] set counter = counter-1; P=$P/.. ; end cd $P; setenv MPWD=$P'
However, I am getting the following error:
while[counter!=0]: No match.
P=/net/devstorage/home/rghosh/..: Command not found.
end: Too many arguments.
and my script is not working as intended. I have been reading up on csh from here.
csh
I am writing a csh alias so that I can use the following bash function in my csh :
function up( )
{
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
P=$P/..
done
cd $P
export MPWD=$P
}
(I stole the above bash function from here)
I have written this:
alias up 'set LIMIT=$1; set P=$PWD; set counter = LIMIT; while[counter!=0] set counter = counter-1; P=$P/.. ; end cd $P; setenv MPWD=$P'
However, I am getting the following error:
while[counter!=0]: No match.
P=/net/devstorage/home/rghosh/..: Command not found.
end: Too many arguments.
and my script is not working as intended. I have been reading up on csh from here.
csh
csh
edited 2 hours ago
Rui F Ribeiro
41.5k1483140
41.5k1483140
asked Jan 21 '13 at 17:03
ChaniChani
229414
229414
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I’m not sure it’s even possible to do a while
loop all on one line.
But there are several fixable errors:
while[counter!=0]
should bewhile ($counter != 1)
(note the spaces before and after the “!=
”).
set counter = counter-1
should be@ counter = $counter – 1
(note the spaces before and after the ‘–
’).
P=$P/..
should beset P=$P/..
–– or better yet,set P="$P/.."
(in case$P
contains space(s).- Which reminds me,
set P=$PWD
should beset P="$PWD"
,cd $P
should becd "$P"
, andsetenv MPWD=$P
should besetenv MPWD="$P"
, all for the same reason. - And, if you do manage to get the
while
loop all on one line to work, you’re probably going to need a;
after theend
.
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using/
– Chani
Jan 22 '13 at 5:26
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial likemkdir –p foo/foo/foo; while { cd foo } pwd; end
.
– Scott
Jan 22 '13 at 16:07
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%2f62032%2ferror-converting-a-bash-function-to-a-csh-alias%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
I’m not sure it’s even possible to do a while
loop all on one line.
But there are several fixable errors:
while[counter!=0]
should bewhile ($counter != 1)
(note the spaces before and after the “!=
”).
set counter = counter-1
should be@ counter = $counter – 1
(note the spaces before and after the ‘–
’).
P=$P/..
should beset P=$P/..
–– or better yet,set P="$P/.."
(in case$P
contains space(s).- Which reminds me,
set P=$PWD
should beset P="$PWD"
,cd $P
should becd "$P"
, andsetenv MPWD=$P
should besetenv MPWD="$P"
, all for the same reason. - And, if you do manage to get the
while
loop all on one line to work, you’re probably going to need a;
after theend
.
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using/
– Chani
Jan 22 '13 at 5:26
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial likemkdir –p foo/foo/foo; while { cd foo } pwd; end
.
– Scott
Jan 22 '13 at 16:07
add a comment |
I’m not sure it’s even possible to do a while
loop all on one line.
But there are several fixable errors:
while[counter!=0]
should bewhile ($counter != 1)
(note the spaces before and after the “!=
”).
set counter = counter-1
should be@ counter = $counter – 1
(note the spaces before and after the ‘–
’).
P=$P/..
should beset P=$P/..
–– or better yet,set P="$P/.."
(in case$P
contains space(s).- Which reminds me,
set P=$PWD
should beset P="$PWD"
,cd $P
should becd "$P"
, andsetenv MPWD=$P
should besetenv MPWD="$P"
, all for the same reason. - And, if you do manage to get the
while
loop all on one line to work, you’re probably going to need a;
after theend
.
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using/
– Chani
Jan 22 '13 at 5:26
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial likemkdir –p foo/foo/foo; while { cd foo } pwd; end
.
– Scott
Jan 22 '13 at 16:07
add a comment |
I’m not sure it’s even possible to do a while
loop all on one line.
But there are several fixable errors:
while[counter!=0]
should bewhile ($counter != 1)
(note the spaces before and after the “!=
”).
set counter = counter-1
should be@ counter = $counter – 1
(note the spaces before and after the ‘–
’).
P=$P/..
should beset P=$P/..
–– or better yet,set P="$P/.."
(in case$P
contains space(s).- Which reminds me,
set P=$PWD
should beset P="$PWD"
,cd $P
should becd "$P"
, andsetenv MPWD=$P
should besetenv MPWD="$P"
, all for the same reason. - And, if you do manage to get the
while
loop all on one line to work, you’re probably going to need a;
after theend
.
I’m not sure it’s even possible to do a while
loop all on one line.
But there are several fixable errors:
while[counter!=0]
should bewhile ($counter != 1)
(note the spaces before and after the “!=
”).
set counter = counter-1
should be@ counter = $counter – 1
(note the spaces before and after the ‘–
’).
P=$P/..
should beset P=$P/..
–– or better yet,set P="$P/.."
(in case$P
contains space(s).- Which reminds me,
set P=$PWD
should beset P="$PWD"
,cd $P
should becd "$P"
, andsetenv MPWD=$P
should besetenv MPWD="$P"
, all for the same reason. - And, if you do manage to get the
while
loop all on one line to work, you’re probably going to need a;
after theend
.
answered Jan 22 '13 at 3:46
ScottScott
6,99252751
6,99252751
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using/
– Chani
Jan 22 '13 at 5:26
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial likemkdir –p foo/foo/foo; while { cd foo } pwd; end
.
– Scott
Jan 22 '13 at 16:07
add a comment |
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using/
– Chani
Jan 22 '13 at 5:26
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial likemkdir –p foo/foo/foo; while { cd foo } pwd; end
.
– Scott
Jan 22 '13 at 16:07
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using
/
– Chani
Jan 22 '13 at 5:26
I had to write the while loop in a single line because I was getting a horde of errors while using the the next line facility using
/
– Chani
Jan 22 '13 at 5:26
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial like
mkdir –p foo/foo/foo; while { cd foo } pwd; end
.– Scott
Jan 22 '13 at 16:07
OK, but my point is: have you ever gotten a ‘while loop in a single line’ to work? If yes, please post an example; even if it’s something trivial like
mkdir –p foo/foo/foo; while { cd foo } pwd; end
.– Scott
Jan 22 '13 at 16:07
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%2f62032%2ferror-converting-a-bash-function-to-a-csh-alias%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