bash: "command not found" when calling function defined in ~/.bashrc file in `bash -c` command while opening gnome-terminal tab
To get bash to read and execute ~/.bashrc
on startup, start it as an interactive shell:
gnome-terminal --tab -- bash -ic "set-title hey; exec bash"
Now why didn’t your approach of sourcing the file in a non-interactive shell work? I strongly assume your ~/.bashrc
begins with something like this:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
This lets it return
without doing anything if the shell where it is sourced doesn’t have “i” anywhere in its $-
, i.e. it’s an interactive shell. $-
is a special parameter, man bash
says:
-
Expands to the current option flags as specified upon invocation, by theset
builtin command, or those set by the shell itself (such as the-i
option).