Linked Questions
22 questions linked to/from Why doesn't my Bash script recognize aliases?
1
vote
1
answer
1k
views
Add aliases to .sh files [duplicate]
For some reason, I had to add an alias to my bash. I have added the alias in /root/.bashrc which also contains the following piece of code:
# Source global definitions
if [ -f /etc/bashrc ]; then
...
0
votes
2
answers
2k
views
Why my zsh script doesn't echo anything? [duplicate]
script:
#!/bin/zsh
IFS=$'\n' arr=($(alias | grep 'git' | grep "^[g|\'g]" | sed 's/=.*//' | sed "s/'//"))
echo $arr
These two lines work in the normal command line:
~/test ·······...
-4
votes
1
answer
1k
views
How can I pass aliases from a shell to a script run by it? [duplicate]
$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='...
0
votes
0
answers
165
views
Shell cannot find a command already defined in the .bashrc [duplicate]
I'm trying to write a script that recursively calls to a command that I defined in my .bashrc using alias name-of-function ='path-to-find-it' but each time I get the error command not found. If i copy ...
1
vote
0
answers
62
views
Why cp and mv behave differently in bash script than command prompt? [duplicate]
I have cp and mv commands withaliases preset in my system.
[root@IMSSA ~]# which cp mv
alias cp='cp -i'
/bin/cp
alias mv='mv -i'
/bin/mv
[root@IMSSA ~]#
If I try to replace a file, it ...
1
vote
0
answers
46
views
Bash alias defined in script not working within the script [duplicate]
I found a weird thing:
When I do in the console,
alias a='echo aaa'
a
I get the output aaa as expected. But when I do a script, let's name it script.sh
#!/bin/bash
alias a='echo aaa'
a
and run it ...
16
votes
6
answers
17k
views
Can't use alias in script, even if I define it just above!
I have a very wierd case... If I run a script with /bin/bash, it can't recognize aliases that I set even inside the script. And the most strange thing is
$ cat -n test.sh
1 #!/bin/bash
2 ...
27
votes
3
answers
3k
views
Any command in my terminal that exits with non-zero code closes my terminal window
At first this was a bit funny, like playing "Bash Roulette"
...but now it's getting old lol
Any command in my terminal that exits with non-zero code closes my terminal window
I was told that perhaps ...
12
votes
2
answers
11k
views
bash aliases do not expand even with shopt expand_aliases
I want to run an alias inside a bash -c construct.
The bash manual says:
Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt
In ...
14
votes
5
answers
19k
views
How can I get sudo commands to use the settings in /root/.bashrc
I have customised .bashrc with a number of alias, specifically ll and export LS_OPTIONS='--color=auto'
Unfortunately this does not work when used with sudo, so I also modified /root/.bashrc, but this ...
8
votes
3
answers
15k
views
Can I make scripts use aliases instead of commands?
I have an alias for a command (I'm setting up a Python development environment)
alias python=~/virtualenv/bin/python
so that I can run ~/virtualenv/bin/python by just typing python. Now in my project ...
4
votes
6
answers
1k
views
search a command in PATH with the same name of the script
For example, my script is $HOME/bin/sudo. I'd like to search for an executable in $PATH with the same name, sudo, and run it - but not the script $HOME/bin/sudo itself, otherwise I will run into an ...
1
vote
1
answer
2k
views
how does CentOS load bash_alias file?
I'm used to Ubuntu, where I just create a .bash_aliases file and away you go. In CentOS, how do I get .bashrc to load the .bash_aliases file?
0
votes
2
answers
1k
views
Bash: Alias not recognized in shell interpolation
~$ bash --version
GNU bash, version 5.1.12(1)-release (x86_64-pc-linux-gnu)
~$ alias bab=python
~$ $(echo bab)
bash: bab: command not found
I'd expect bab to be turned to "python", but it ...
1
vote
1
answer
819
views
How to evaluate bash alias before being passed to bash function?
I have defined a test alias as:
alias testalias='python3 -c "f = open(\"/tmp/testopenfile\", \"w+\"); f.write(\"hi\n\")"'
It works fine when I run it directly ...