Error converting a bash function to a csh alias












3















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.










share|improve this question





























    3















    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.










    share|improve this question



























      3












      3








      3








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 hours ago









      Rui F Ribeiro

      41.5k1483140




      41.5k1483140










      asked Jan 21 '13 at 17:03









      ChaniChani

      229414




      229414






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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 be while ($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 be set P=$P/.. –– or better yet, set P="$P/.." (in case $P contains space(s).

          • Which reminds me, set P=$PWD should be set P="$PWD", cd $P should be cd "$P", and setenv MPWD=$P should be setenv 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 the end.






          share|improve this answer
























          • 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











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          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 be while ($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 be set P=$P/.. –– or better yet, set P="$P/.." (in case $P contains space(s).

          • Which reminds me, set P=$PWD should be set P="$PWD", cd $P should be cd "$P", and setenv MPWD=$P should be setenv 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 the end.






          share|improve this answer
























          • 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
















          1














          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 be while ($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 be set P=$P/.. –– or better yet, set P="$P/.." (in case $P contains space(s).

          • Which reminds me, set P=$PWD should be set P="$PWD", cd $P should be cd "$P", and setenv MPWD=$P should be setenv 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 the end.






          share|improve this answer
























          • 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














          1












          1








          1







          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 be while ($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 be set P=$P/.. –– or better yet, set P="$P/.." (in case $P contains space(s).

          • Which reminds me, set P=$PWD should be set P="$PWD", cd $P should be cd "$P", and setenv MPWD=$P should be setenv 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 the end.






          share|improve this answer













          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 be while ($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 be set P=$P/.. –– or better yet, set P="$P/.." (in case $P contains space(s).

          • Which reminds me, set P=$PWD should be set P="$PWD", cd $P should be cd "$P", and setenv MPWD=$P should be setenv 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 the end.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 like mkdir –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











          • 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

















          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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          CARDNET

          Boot-repair Failure: Unable to locate package grub-common:i386

          濃尾地震