Tagged Questions
0
votes
0answers
46 views
Using an alias or function to run process in background, with dot files [closed]
Drews-MacBook-Pro:5493040 drewgross$ function s() { subl "$@" & }
Drews-MacBook-Pro:5493040 drewgross$ s .profile
[1] 1268
-bash: .profile: command not found
Drews-MacBook-Pro:5493040 drewgross$
...
2
votes
3answers
146 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 ...
3
votes
2answers
153 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 ...
87
votes
9answers
5k 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 ...
2
votes
1answer
150 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
245 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 ...
4
votes
2answers
198 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
597 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 ...
10
votes
1answer
896 views
bash 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 ...
1
vote
3answers
1k 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. ...