I have the following line in my .bashrc: #!/usr/bin/env bash alias see='nano --view $1'  But now shellcheck is producing a high priority warning:  Aliases can't use positional parameters, use a function instead.  Reasonable except for one thing: it works fine! What's going on?
121043
I want to create an alias that can handle parameters ($1), and can fall back to a default value if a parameter is not provided.  For example, $ alias foo='NUM=${1:-42}; echo $NUM'  Invoked without params it works as I want: $ foo 42  But invoked with a param, it prints both my value and default value: $ foo 69 42 69  I don't understand why it's this way. How should it be done properly?  How can I debug this kind of problem myself?
35087
In scripts, first line should specify the path to interpreter. But on different servers Linux, Unix, or BSD this path could be different.  What is more preferable?  #!/usr/bin/env bash    or  #!/bin/bash
108737
Is it possible to forcibly add a timing alias (for lack of a better way to phrase it) to every command in bash? For example, I would like to have a specific user who, whenever a command is run, it is always wrapped either with date before and after, or time. Is this possible, and, if so, how?
13462
In my ~/.bashrc, I have an alias called yy as follows  alias yy="youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]'"   But I often run it this way  yy &lt;url list&gt; &amp;&amp; exit   I would like to make it simpler and convert it to a simple alias called yye.  yye &lt;url list&gt;   Would anyone please advise how to carry out this alias definition?
117426
Why when I try to write a function just in one line into .bashrc file,  list(){ ls -a }   I get error?  bash: /home/username/.bashrc: line num: syntax error: unexpected end of file   but when I write it in multi line it's ok?  list(){     ls -a }
42475
How do I resolve a variable in a subshell inside of "bash -c"?  In the following, the second subshell -- the one with an "echo" inside -- resolves correctly.  The first subshell -- with "touch" -- does not.  /bin/bash -c "\ A=/tmp/foo; \ echo $( touch \$A;  ); \ echo $( echo in subshell, \$A; ); \ "
48283
I am taking the Linux Essentials class and was doing well until I hit the scripting chapter. I simply do not understand these concepts.  Wondering if someone can break the following down into ultra simplistic terms or point me to a better reference to learn it. I'm currently using netacad's curriculum.        From the text book (with minor formatting changes):     There are some special variables in addition to the ones you set. You   can pass arguments to your script:  #!/bin/bash echo "Hello $1"       A dollar sign followed by a number N corresponds to the Nth argument   passed to the script. If you call the example above with ./test.sh the   output will be Hello Linux. The $0 variable contains the name of the   script itself.      After a program runs, be it a binary or a script, it returns an exit   code which is an integer between 0 and 255. You can test this through   the $? variable to see if the previous command completed successfully.     I understand how to assign variables and how they work with the $ but the whole issue with $0 and $1 -- I just don't get it.    Any help would be much appreciated.
1256
In my ~/.bashrc file reside two definitions:   commandA, which is an alias to a longer path commandB, which is an alias to a Bash script   I want to process the same file with these two commands, so I wrote the following Bash script:    #!/bin/bash  for file in "$@"     do     commandA $file     commandB $file done   Even after logging out of my session and logging back in, Bash prompts me with command not found errors for both commands when I run this script.  What am I doing wrong?
105902
I like to encapsulate commands within shell-functions using the same name. But to avoid the shell-function calling itself recursively, I specify the complete path of the command as the following example:  less() {     test 0 -lt $# &amp;&amp; echo -ne "\e]2;$@\a\e]1;$@\a"     # Window title     /usr/bin/less -i -rS --LONG-PROMPT --shift 5 "$@" }   But for some commands, I do not want to specify the path because it may change. I would prefer to use $PATH.  For instance, my following attempt failed to call mvn command using backslash: \mvn  mvn()  # colorizes maven output {         \mvn "$@" 2&gt;&amp;1 | #here: the shell-function recursively calls itself indefinitely         sed -u '                                                  s/^\[ALL\].*/\o033[1;37m&amp;\o033[0m/   s/^\[FATAL\].*/\o033[1;31m&amp;\o033[0m/   s/^\[ERROR\].*/\o033[1;31m&amp;\o033[0m/ s/^\[WARNING\].*/\o033[1;33m&amp;\o033[0m/    s/^\[INFO\].*/\o033[1;37m&amp;\o033[0m/   s/^\[DEBUG\].*/\o033[1;36m&amp;\o033[0m/   s/^\[TRACE\].*/\o033[1;32m&amp;\o033[0m/' }   What is the best way to bypass this issue?   Please do not suggest to use a different shell-function name.  (I usually use bash but I am interested about other shell solutions.)
37969
How to create an alias that actually extends another alias of the same name in Bash?  Why:  I used to have GREP_OPTIONS set on .bashrc to something like this:  GREP_OPTIONS="-I --exclude=\*~"   I also had a script (let us say, setup-java.sh) which I would call before working on some Java projects. It would contain the line:  GREP_OPTIONS="$GREP_OPTIONS --exclude-dir=classes"   If I also use Sass, then I would call setup-sass.sh which contains the line:  GREP_OPTIONS="$GREP_OPTIONS --exclude-dir=\*/.sass-cache"   But  and apparently the standard solution is either create an alias or some script...
64283
I have added alias ll='ls -la' in /etc/bash.bashrc but sudo ll is not working. Is there a way to "source" bash.bashrc? In a related post, another user suggesting creating an alias for sudo with a space after it. Eg. alias sudo='sudo ' but there wasn't any context to this answer. Should I add this to my bashrc? Seems hackish.  What is the correct method for adding an alias for my sudo one-off commands?
81980
On a server when I login as root I see .bashrc (Ubuntu 10.10).  On my Mac I have a .bash_profile  Does Ubuntu always have only a .bashrc file and not .bash_profile? (I'm just confused, so asking, I realize they are different o/s's but maybe there is a relationship somehow?)  On my server, I want to create an alias, should I put it in .bashrc?  What if I want this alias to be applied so all users can use it?
89584
I have an alias defined in my .bashrc  alias l.='ls -d .* --color=auto'   It's very useful :) but it doesn't work via ssh:  $ ssh localhost l. bash: l.: command not found   Why is that?
101526
An alias for ls command in ~/.bashrc file aliased with this one:  alias ls='ls --color=auto'   then, when I run ls command in terminal aliased ls(ls --color=auto) runs. but my question is how can I run original ls only and only ls alone without extra argument and without solving problem with deleting aliased entry? since when I delete this entry I can run it in simple ls.
26823
I've hacked on a lot of shell scripts, and sometimes the simplest things baffle me. Today I ran across a script that made extensive use of the : (colon) bash builtin.  The  seems simple enough:   : (a colon)        : [arguments]         Do nothing beyond expanding arguments and performing redirections. The return status is zero.    However I have previously only seen this used in demonstrations of shell expansion. The use case in the script I ran across made extensive use of this structure:  if [ -f ${file} ]; then     grep some_string ${file} &gt;&gt; otherfile || :     grep other_string ${file} &gt;&gt; otherfile || : fi   There were actually hundreds of greps, but they are just more of the same. No input/output redirects are present other than  the simple structure above. No return values are checked later in the script.  I am reading this as a useless construct that says "or do nothing". What purpose could ending these greps with "or do nothing" serve? In what case would this construct cause a different outcome than simply leaving off the || : from all instances?
48133
I like to use tools like history, script, and asciinema to record and review xterm (i.e. bash/sh) sessions for typical, general administration reasons, and also, sometimes for comprehensive study/revision; as a learning tool.   I thought of setting the default $SHELL as a direct path to said tools and/or commands, like:   /bin/script transcript.log;  /bin/asciinema rec -w0.5 term_log.json;  But these tools typically rely on having a default $SHELL set (i.e. /bin/bash, /bin/sh, /bin/zsh, etc.). Also, I feel like re-defining system variables (i.e. $SHELL, $TERM, etc.) or trying to get it working with config (*.conf) and dot (~/.bashrc / ~/.bash_profile) files is gona be riddled with all kinds of holes and potential problems. However, every time I decide or realize that I want a transcript of a session, it's after the fact, or I'll be halfway through the interesting part already, or some such scenario.   What's the correct, or best practice to set something like this up to simply log everything (preferably stdin, stdout (and stderr when applicable), etc.) automatically?
118067
I'd like to be able to quickly, on-the-fly add (and list/remove) command aliases so that they persist between shell restarts (as if they were added to .bashrc). Are there any ready utilities/scripts/whatever that can help me with that?  Ideally the uses case would look like:  aliasutil add "gcm" "git checkout master" aliasutil add "gfp %1" "git push --force %1" aliasutil list aliasutil remove "gcm"