Linked Questions

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 ...
Nate's user avatar
  • 121
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 ·······...
Yuchen Zhang's user avatar
-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='...
Tim's user avatar
  • 107k
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 ...
Mrcs's user avatar
  • 1
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 ...
prado's user avatar
  • 970
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 ...
karlosss's user avatar
  • 527
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 ...
nichen's user avatar
  • 275
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 ...
Alexander Mills's user avatar
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 ...
Tom Hale's user avatar
  • 33.3k
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 ...
Milliways's user avatar
  • 1,408
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 ...
phunehehe's user avatar
  • 20.6k
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 ...
eadmaster's user avatar
  • 1,733
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?
Thufir's user avatar
  • 1,970
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 ...
Nitz's user avatar
  • 143
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 ...
Machinexa's user avatar
  • 143

15 30 50 per page