2
votes
3answers
42 views

how to prevent alias expansion by `eval` to an arbitrary alias, and keep the endless loop protection on a function?

IMPORTANT: do not use eval! (I learned this later..) In a function, eval expands sleep to its alias, so I prevent the endless loop this way: function FUNCexecEcho() { echo "EXEC: $@"; shopt -u ...
4
votes
2answers
311 views

How to test if command is alias, function or binary?

I have command foo, how can I know if it's binary, a function or alias?
2
votes
3answers
367 views

What are commands to find shell keywords, built in functions and user defined functions?

I was discussing with my friend on how the commands are parsed in the shell, and he told me that bash searches the command in following order List of aliases List of shell keywords List of ...
5
votes
3answers
736 views

How to set an alias on a per-directory basis?

Suppose you have an alias go, but want it to do different things in different directories? In one directory it should run cmd1, but in another directory it should run cmd2 By the way, I have an ...
2
votes
1answer
212 views

awk function with a number parameter for the column you want to print

I want to use my awk shortcut as a function, so that I can pass the column number which then prints me the output. My aliases are: alias A="| awk '{print \$1}' alias G="| grep -i' Instad of typing: ...
2
votes
0answers
358 views

How to enable `sudo` with custom functions?

Recently I learned you can enable sudo for custom aliases as follows: alias sudo='sudo ' # note: the space is required! The reason this works is the following: If the last character of the ...
137
votes
10answers
12k views

In Bash, when to alias, when to script, and when to write a function?

It's taken me almost 10 years of Linux usage to ask this question. It was all trial and error and random late-night internet surfing. But people shouldn't need 10 years for this. If I were just ...
4
votes
2answers
245 views

Combine two commands in .bash_profile

In my .bash_profile file, I'd like to setup a single command alias that is two commands that execute one after another. The first command takes an argument from the command line and the second is ...
2
votes
2answers
708 views

creating simple command for sudo apt-get install?

I need to run these commands very often: sudo apt-get install <package> sudo apt-get remove <package> Can I make it simple like: install <package> remove <package> I ...
1
vote
3answers
2k views

alias or bash function does not work

When I create alias wd='ps -ef | grep java | awk {'print $2 " " $9'} | egrep "(A|B|C|D)"' or function wd () { ps -ef | grep java | awk '{print $2}' ... } in my .bashrc file, I get errors. ...
18
votes
1answer
1k views

Aliases vs functions vs scripts

This site says, "Shell functions are faster [than aliases]. Aliases are looked up after functions and thus resolving is slower. While aliases are easier to understand, shell functions are preferred ...