Score:3

Can not call defined funtions from .bashrc

cn flag

I have a function in .bashrc like this:

function gs () {
  cmm="$1"
  if test -z "$cmm"
  then
    cmm="This is Manh Cuong's commit ."
  fi
  
  git add . && git commit -m "$cmm" && git push
}

It worked well with gs and gs "new commit" commands in terminal. But I have just installed zsh, oh-my-zsh on my Ubuntu 20.04 Asus laptop. Then I call gs or gs "new commit", it does not work anymore. I do not know how to fix it. Could anybody help me. Thank you very much.

bac0n avatar
cn flag
`cmm=${1:-"This is Manh ..."}`, you don't really need that if-statement. `${parameter:-word}` expands to `word` if `$parameter` is "empty".
Claire Duong avatar
cn flag
Oh I have just known that, I am going to update my .zshrc with this option
Artur Meinild avatar
vn flag
@bac0n is that for zsh only, or does it also work for bash?
bac0n avatar
cn flag
bash, dash, ksh, zsh
Score:7
cn flag

If you're running zsh shell then you have to put this in ~/.zshrc instead of ~/.bashrc.

Once you've added it there, you can either open a new terminal or run source ~/.zshrc to use it.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.