简体   繁体   中英

When using alias containing cd and echos, an arrow appear but nothing else

I made a pretty long alias and I can't get it to work. I put it in ~/.bash_profile. Here is it:

alias venga='cd ~/Users/clem/Desktop/venga/ ; echo "Vous êtes dans le dossier venga de votre site web." ; echo " " ; echo "Pour ajouter un commit, utilisez :" ; echo "git commitcommit -am "Message du Commit" ; echo " " ; echo "Pour envoyer le dossier vers GitHub, utilisez :" ; echo "git push origin master" ; echo " " ; echo "Pour ajouter un fichier à git utilisez :" ; echo "git add nomdufichier.xx"'

Here's the output:

$ venga
>

When I hit enter, other arrows appear below. I don't know what to do.

You have an unclosed quote, due to the unescaped quote in:

echo "git commitcommit -am "Message du Commit" ;

The > is a continuation prompt, because the shell is waiting for you to close the quote. You don't need an alias to see this happening:

$ echo "Hello
>
>
> world"
Hello


world
$

You probably intended to have:

echo "git commit -am \"Message du Commit\""

... or ...

echo 'git commit -am "Message du Commit"'

But quoting in the shell is a bit of a minefield at the best of times.

A cleaner way of outputting many lines to stdout is cat with a here document:

 cat << END
 Hello
 "World"
 DONE

Write this as a function, not an alias:

venga() {
  cd /Users/clem/Desktop/venga/ || {
    echo "Impossible d'accéder au répertoire du site Web"
    return
  }
  echo 'Vous êtes dans le dossier venga de votre site web.'
  echo
  echo 'Pour ajouter un commit, utilisez :'
  echo 'git commitcommit -am "Message du Commit"'
  echo 
  echo 'Pour envoyer le dossier vers GitHub, utilisez :'
  echo 'git push origin master'
  echo
  echo 'Pour ajouter un fichier à git utilisez :'
  echo 'git add nomdufichier.xx'
}

Allows error handling, makes the code much easier to read -- and moots the quoting concerns that caused you trouble with the alias form.

(I also fixed up ~/Users/clem/Desktop/venga to /Users/clem/Desktop/venga , as the former was looking for something like $HOME/Users/clem/Desktop/venga , and you probably don't have Users under $HOME ).

You have mismatched ".

I think the guilty part is:

echo "git commitcommit -am "Message du Commit"

Here's the fixed version:

alias venga='cd ~/Users/clem/Desktop/venga/ ; echo "Vous êtes dans le dossier venga de votre site web." ; echo " " ; echo "Pour ajouter un commit, utilisez :" ; echo "git commitcommit -am \\"Message du Commit\\"" ; echo " " ; echo "Pour envoyer le dossier vers GitHub, utilisez :" ; echo "git push origin master" ; echo " " ; echo "Pour ajouter un fichier à git utilisez :" ; echo "git add nomdufichier.xx"'

Also you'll probably be better off putting this instructions in a separate file, that you just cat , rather than having a number of echos.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM