Skip to main content

All Questions

Tagged with
-1 votes
1 answer
156 views

Override tr in ~/.bashrc

I'm trying to create a function to translate words via a custom script: function mean() { ~/scripts/translate.sh $1 } I would prefer the function to be named tr, as it is much shorter and faster ...
algonell's user avatar
3 votes
1 answer
248 views

How to overload / customize bash (or any other shell) commands handler?

When in bash some non existing command is run, corresponding error message appears: $ non-existent-command non-existent-command: command not found Is it possible to customize this behavior? I would ...
Anton Samokat's user avatar
2 votes
0 answers
47 views

Can't unalias then redefine as a function in the same conditional [duplicate]

Here is a simplified implementation of an issue in my bash/zsh aliases file: alias foobar='echo bar' # this is out of my control if true; then unalias foobar echo we got inside the conditional ...
Adam Katz's user avatar
  • 4,132
3 votes
1 answer
227 views

Making simple backup alias / function?

OK, so all I really want to do is backup single files as a time in the current directory with '.bak' extension. Here is my current function that does this (jsyk, using Rocky Linux): function backup { ...
GregTheHun's user avatar
1 vote
1 answer
290 views

How to call many shell functions from sudo?

I have a huge alias file sourced by ~/.bashrc or ~/.zshrc which contains both simple aliases and more functions for more complex stuff: # example aliases alias "sudo=sudo " alias "...
Polizi8's user avatar
  • 285
0 votes
2 answers
468 views

Finding duplicate aliases and functions in a script (.bashrc etc)

This site says that functions are faster than aliases, but he rightly points out that aliases are easier to understand - when you want something very simple and do not need to consider passing ...
YorSubs's user avatar
  • 651
1 vote
2 answers
239 views

bash, pass an argument to the 'history' command

I do the following to make history more sensible (i.e. seeing when a command is run can be fairly critical when troubleshooting) shopt -s histappend; # Append commands to the bash history (~/....
YorSubs's user avatar
  • 651
1 vote
1 answer
765 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
1 vote
1 answer
621 views

bash, "\" in an alias or function

I use Windows and Linux a lot, and sometimes I type cd\ from Windows muscle-memory, so I tried to alias that, alias cd\='cd /' but that doesn't work (presumably because \ is an the escape character in ...
YorSubs's user avatar
  • 651
26 votes
1 answer
16k views

How to make a multiline alias in Bash?

I want to make an alias for a multiline ​command to call it faster then copying-pasting-executing it from a text file each time. An example for such command is this execute-a-remote-updater command: ( ...
timesharer's user avatar
0 votes
1 answer
100 views

bash function to replace every occurence of text in directory and subdirectories

I found (on Google) this perfectly working line to replace every occurences in all files in my directory and subdirectories: grep -lr previoustext | xargs sed -i 's/previoustext/newtext/g' It works ...
Zkyem's user avatar
  • 3
0 votes
0 answers
18 views

Alias or Function for a Command [duplicate]

Sometimes (or may be all the time) an Alias and Function for a command works the same way. For example, following Alias and Function of Ping Command: alias Pingoogle='ping -c 3 google.com && ...
Salman Ahmed's user avatar
0 votes
1 answer
102 views

$@ in alias inside script: is there a "local" $@?

I have aliased pushd in my bash shell as follows so that it suppresses output: alias pushd='pushd "$@" > /dev/null' This works fine most of the time, but I'm running into trouble now using it ...
Théophile's user avatar
6 votes
1 answer
563 views

Unexpected behavior of Bash script: First executes function, afterwards executes alias

When I execute the following script #!/usr/bin/env bash main() { shopt -s expand_aliases alias Hi='echo "Hi from alias"' Hi # Should Execute the alias \Hi # Should Execute the ...
Porcupine's user avatar
  • 2,146
0 votes
0 answers
53 views

What is the correct way to assign a function containing chained commands to an alias in .bashrc?

I wish to invoke an alias as follows: alias_name arg0 arg1 arg2 arg0 = filename arg1 = General string arg2 = String representation of last command The aim is that by calling the alias and passing ...
MarkMark's user avatar
  • 593

15 30 50 per page