Score:0

Bash Function/Alias name collision causes seg fault

me flag

The problem in this post also happened to me. mkdir crashes bash

I couldn't comment there because no reputation. Can anyone elucidate why this happens? It happens at runtime Not when the function is loaded. Here is the paste of the identical issue.

md() 
{  
    [ $# -eq 0 ] && { echo "$0 dirname [permissions]"; return; }
    [ -d "$1" ] && { echo "%1 already exists!"; return; }
    mkdir -m ${2:-0755} -p "$1"
}

"Problem was that I had previously had an alias like alias md="mkdir" so when bash parsed the new bash function, it expanded the md() to mkdir() and the function became infinitely recursive and crashed the shell. "

I felt this issue was aptly found but i do not understand the reasoning. I don't understand any possible reason the alias expansion is misdirecting the fully qualified shell function. Backwards right?

Sorry for the dupe, please read why before a callout.

hr flag
Aliases are really just text replacement macros - so when you try to *define* `md() { ... }` after defining `md=mkdir` you actually end up with `mkdir() { ... }`. Try printing out the function defs with `declare -p -f md` and `declare -p -f mkdir` to see what I mean.
Score:0
me flag

"Aliases are really just text replacement macros - so when you try to define md() { ... } after defining md=mkdir you actually end up with mkdir() { ... }. Try printing out the function defs with declare -p -f md and declare -p -f mkdir to see what I mean." – steeldriver

zi@zi-top:~$ declare -p -f nd
bash: declare: nd: not found
zi@zi-top:~$ declare -p -f mkdir
mkdir () 
{ 
    mkdir -p "$@"
}
zi@zi-top:~$ nd () {
        mkdir -p "$@"
}
zi@zi-top:~$ declare -p -f nd
bash: declare: nd: not found

I see that what steeldriver said is true, i think it`s a strange architectural decision with prob some kind of reasoning in the code is text bashism wurl. Thanks!

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.