All Questions
Tagged with alias shell-script
66 questions
0
votes
1
answer
62
views
Get a list of all user's commands from a non-interactive shell
I am writing a script that would automatically suggest some new aliases/functions to be added to a user's shell config. Before doing that, however, I would like to make sure the aliases being ...
0
votes
1
answer
66
views
Is there a way I can use .bash_aliases in a shell-scripts? [duplicate]
Is there a way I can use bash aliases from my .bash_aliases file within a shell-scripts?
I thought of something like including
source "$HOME/.bash_aliases into my script
but it does not work.
0
votes
1
answer
281
views
How to show help for some bash command in less (like man do) rather than print it to console
For example, there is no manual pages for trap command. Running:
man trap
will give:
No manual entry for trap
Running:
trap --help
will print help straight to bash console without using less like ...
1
vote
1
answer
477
views
Unix Command (and bash alias) or script to band/unban IP addresses in Fail2ban without having to lookup and specify "jail name"
I am creating a bash alias (or possibly a script) to ban and unban IP addresses with fail2ban on Ubuntu 20.04.
The bash syntax I am using to unban IP address is:
fail2ban-client set YOURJAILNAMEHERE ...
2
votes
0
answers
286
views
Order in which files within /etc/profile.d are sourced in CentOS 7.9? (for defining aliases)
I have a question related to aliases/environment variables on CentOS 7.9. I am trying to make an alias for ll with:
echo 'alias ll="ls -alhF --color=auto"' > /etc/profile.d/Z-alias-ll.sh
...
1
vote
1
answer
149
views
use aliases in bash script
I use aliases in my code, it works the first time and shows the current time, but the second time, when I call it shows past time(time showed before instead of current time)
GNU nano 6.2 ...
1
vote
2
answers
2k
views
/etc/zshrc is not applied when log in
I have no idea why having aliases that are applied to all interactive terminal (i.e., my user account and sudo) is so difficult. Most web search result were about BASH, but my shell is ZSH (Manjaro ...
1
vote
0
answers
316
views
Minify bash command with arguments
Want to minify bash command using arguments.
I am often checking the internet provider's and other Free and Public DNS Servers with the code below running in tmux, but wondering, how this can be ...
1
vote
3
answers
3k
views
How do I make an alias for a command with sudo
I want to add two aliases, so one executes a command when non sudo, and the other executes a command when sudo, like this:
alias v = 'nvim'
alias 'sudo v' = 'sudo -E nvim '
I also have set alias sudo=...
1
vote
1
answer
189
views
How to send output to next input line?
This my snippet alias hst="history 1 -1 | cut -c 8- | uniq | fzf ".
when I run hst
The output is
$ ~ hst
(the output from hst)
$
This is what I want
$ ~ hst
$ (the output from hst)
Example
...
-1
votes
1
answer
1k
views
bashrc + why source not refresh the .bashrc file
we add the following line to bashrc file
alias reboot="echo you not allowed to do reboot on this machine - sorry"
so we get
more ~/.bashrc
# .bashrc
# User specific aliases and functions
...
0
votes
0
answers
220
views
Why doesn't creating file with echo work for remote directories in this script?
I aliased the following script:
#!/usr/bin/bash
if [[ -d "template.html" ]]; then
:
else
cp -n /home/$(whoami)/CS/Software/Pollen/template.html .
fi
/usr/bin/echo "#lang pollen
[...
1
vote
1
answer
708
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 ...
-2
votes
2
answers
555
views
Kali Linux - run './pycharm.sh' by running 'pycharm' in terminal
Currently I need to access the folder in my desktop, and then a bin subfolder to reach ./pycharm.
So I want to automate all of:
cd Desktop
cd pycharm-community-2021.3.1
cd bin
./pycharm.sh
to
pycharm
...
2
votes
2
answers
1k
views
Why do I have to use this command twice to execute it?
I made an alias alias goto="cd $@ && source ~/.zshrc" and it works, but only if I execute it twice. Even after I execute it twice in one shell, and if I want to move to another dir, ...
0
votes
2
answers
212
views
Is escaping shell aliases in scripts useful when executing scripts?
Does escaping bash aliases make any sense in any - not sourced and normally run - shell scripts?
Consider the simplest situation with ls for which many users have re-defined its functioning with an ...
1
vote
2
answers
204
views
Make alias from existing alias
I have 2 separate files, which are both sourced from my .zshrc, one of them (the first one) is defining this alias:
alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
problem is that ...
1
vote
1
answer
217
views
How to set an environmental variable from another script?
I set a variable WORKSPACE="$(git rev-parse --show-toplevel)" in ~/.bashrc - which essentially sets $WORKSPACE to the root of the git repository
so that I can write alias for some of the ...
-1
votes
1
answer
60
views
How to make .bashrc alias that runs an .sh file containing a second alias, and then runs that second alias?
Is it possible for me to do what is described in the title?
Lets say I have a script "initstuff.sh" and within that script there is an alias "shalias" that runs some stuff. Putting ...
1
vote
2
answers
2k
views
How to make bash alias work with command inclusion i.e. $() (the dollar sign and parenthesis)
I used to have aliases like:
alias mount-open="sudo mount $(sudo blkid | gawk '/2tb-open/ { print substr($1, 0, 9) }') 2tb-open"
I can't be 100% sure that it was the same, but 100% it was a ...
0
votes
2
answers
118
views
Running a script when a particular command is run
I want to run "./dothis.sh" if someone executes "cat abc.txt"
Is there some way to do this without using alias?
I want to use this for strengthening security of some specific files ...
3
votes
1
answer
3k
views
alias inside a script returns command not found
Using bash in a Debian system.
bash --version
GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later &...
0
votes
2
answers
619
views
Executing alias string command
I wrote a simple script to go through my development project directory and add an alias shortcut for each one:
shopt -s dotglob #Use shopt -u dotglob to exclude hidden directories
find ~/development/*...
0
votes
2
answers
86
views
sudo misinterpreting aliases
In my ~/.bashrc I have the alias link='ln -sf' set, and it's working accordingly during my shell sessions.
However, for root protected locations, where I need to use sudo in the command beginning, it ...
0
votes
1
answer
422
views
echo alias prints space between env variable and first argument
have a weird problem..... Im configuring my arch setup and one of my aliases isnt working.....
alias es='echo $SCRIPTDEST/$1'
For some reason it prints a space between $SCRIPTDEST/ and $1, ruining ...
2
votes
1
answer
114
views
pass multiple search terms to text browser via bash_aliases in prompt
I want to achieve a bash alias so that I can type just:
$> lynxsearch most popular unix text browsers
$> w3msearch most popular unix text browsers
(or the search terms within quotes or ...
0
votes
2
answers
1k
views
Can't I define aliases (using `export`) that are in my current directory? Doing so gives a `not found` message
TLDR: have to define an alias/variable using the export command, I can't use the full path and using a relative path (i.e. defining the alias while in the directory directly above what I want to ...
1
vote
2
answers
741
views
alias: backup & and edit file
I need to backup files (usually images) before editing (and overwrite) them.
Currently I do it by:
cp file.jpg ~/BACKUP/file.jpg
exiv2 BLABLABLA file.jpg
How can I do it with a single command?
e.g.
...
1
vote
0
answers
30
views
how to remove leading space in command line argument [duplicate]
I am losing my mind here.. have tried every combination of functions that strip whitespace but I can't get rid of this particular whitespace
I want to write a convenience alias so that typing
runit ...
2
votes
1
answer
98
views
How to make alias interpretive?
I have a list of servers I often connect to, named like server001, server002... server999. I don't want to store 1000 alias hardcoded with these server names. I also don't want to write a function and ...
0
votes
1
answer
72
views
set alias to read variable and then use in second command; only works when I execute them manually
I am with CentOS 7 and I want to bind an alias to launch PostgreSQL shell(psql). I defined this alias and append it in /etc/profile.d/alias:
alias psql-local="read -p \"PSQL: enter the DB to connect: ...
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 ...
1
vote
1
answer
3k
views
Shell Script To CD and Run a Python Script
OK, I know that there is a lot like this question but I literally get nothing.
The thing i need is a script that cd's to /home/project then runs python3 pyscript.py
I created an alias to cd alias name=...
0
votes
1
answer
160
views
How can I improve below alias?
I want to run less -F command on latest updated log file of one binary (which creates logs with names which start with xtest*) which is in logs directory.
I was able to create below alias in csh, but ...
-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
1
answer
730
views
Override `cd` or other builtin functions more than once
Say I have this bash function:
cd(){
builtin cd "$@"
echo "do my own thing"
}
the problem is that if I override cd in another place, only 1 override will count, any other override will be ...
0
votes
0
answers
23
views
Refresh command output in alias [duplicate]
When I set in .bashrc something like:
alias="docker stop $(docker ps -aq)"
or
alias="echo $(ls -l ~)"
obviously never refreshes the command output in $(), so is an string...
So, my question is, ...
0
votes
0
answers
57
views
Variable expansion succeeds with echo but fails without a command (execution by expansion) [duplicate]
I created a file nano ~/uncwe/configurations/variables.sh. This file contains:
set -a
rse="~/${repo}/internal_software/rse.sh"
set +a
I sourced the file, then tried to execute:
${rse}
bash ${rse}
...
-2
votes
1
answer
87
views
Sourcing works manually but fails when done from script [duplicate]
Using curl as in:
bash <(curl -s https://raw.githubusercontent.com/user/repo/master/script.sh | tr -d '\r')
I executed some remote script.
The remote script includes the following two aspects:
...
1
vote
1
answer
314
views
How to set an alias upon command execution?
I want other developers to have some convenient methods. Therefore I want to give them a script, that automatically sets an alias.
E.g the command grunt compileModule:[modulename] should set the ...
16
votes
4
answers
23k
views
How to turn globbing on and off?
Within my ~./bashrc in an alias I have turned of globbing like this.
alias x='set -f;. any.sh'
But which command enables globbing again or should I set this options in any.sh?
Any response is ...
16
votes
6
answers
16k
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 ...
3
votes
3
answers
65
views
Use commands under directory only for interactive use?
I have a bin/ under $HOME. This contains some augmented versions of common commands. Hence, I don't want these commands to be used by scripts, but only to be used in interactive use.
Is the best I ...
0
votes
1
answer
3k
views
How to create an alias to run a command and exit in bash?
Here is my alias.
alias myAlias='myScript --option& && exit'
I want to run the script myScript with option option in background and then exit from bash. I want to set it up as an alias ...
1
vote
2
answers
2k
views
deferring argument in "alias" in .bashrc
I work with LINUX (ubuntu 14)
My newly purchased laptop forces me to use the bash shell, and
it has .bashrc. I used to use the C-shell before that and tried to copy
its aliases from .cshrc to .bashrc ...
5
votes
2
answers
4k
views
executing alias on variable in bash
I came upon this strange behaviour in my bash script.
#!/bin/bash
V=a
alias $V="echo test"
echo $(a) #returns 'test'
echo $($V) #returns ...'a: not found'
Is there any ...
0
votes
3
answers
2k
views
What are some of the most useful aliases and bash scripts? [closed]
I just picked up some basic bash over at Codecademy today. I was curious what some commonly-used or personal favorite aliases and bash scripts are out there to put in my bash_profile document. Is ...
3
votes
1
answer
41
views
On using $hash_array[$(global_alias)]
Identical code works on one system, fails on another:
% zsh --version
zsh 5.0.7 (x86_64-pc-linux-gnu)
% typeset -A frobozz
% alias -g foo='echo xyz'
% frobozz[$(foo)]=9
% echo ${(kv)frobozz}
xyz 9
% ...
2
votes
2
answers
170
views
Forcing the expansion of a global alias in part of a word
I have a couple of scripts /tmp/foo/bar.sh and /tmp/foo/baz.sh, the look like this:
# /tmp/foo/bar.sh
alias -g __FILE__='${(%):-%x}'
alias -g __DIR__='${${(%):-%x}%/*}'
printf "sourcing %s\n" ...
0
votes
3
answers
822
views
bash script not creating alias and not updating $PS1 [duplicate]
I thought I will write a bash script to set the alias I frequently use, and also to change the command promt.
Below is my script.
#!/bin/bash
# Make useful aliases
alias c='clear'
alias p='pwd'
...