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/* -prune -type d | while IFS= read -r d; do      cur_dir="${d##*/}"     cmd="alias ${cur_dir}=\"code $d\""     echo "executing: $cmd"     $cmd done   And the output looks like this:  executing: alias project-1="code /home/my_user/development/project-1" ./alias_for_projects.sh: line 6: alias: /home/my_user/development/project-1": not found ...   If I copy and run the command:  alias project-1="code /home/my_user/development/project-1"   it just works... How do I fix my script?
7095
$ ls -l /tmp/test/my\ dir/ total 0   I was wondering why the following ways to run the above command fail or succeed?  $ abc='ls -l "/tmp/test/my dir"'  $ $abc ls: cannot access '"/tmp/test/my': No such file or directory ls: cannot access 'dir"': No such file or directory  $ "$abc" bash: ls -l "/tmp/test/my dir": No such file or directory  $ bash -c $abc 'my dir'  $ bash -c "$abc" total 0  $ eval $abc total 0  $ eval "$abc" total 0
10701
I am looking for a way to execute some console commands automatically when a command-prompt is opened in Windows, specifically to set some command aliases.  For example, when a command-prompt is opened, I want a command such as the following to be automatically run so that I can use ls instead of dir.  doskey ls=dir   How can this be done?
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...
26088
I find myself repeating a lot of:  mkdir longtitleproject cd longtitleproject   Is there a way of doing it in one line without repeating the directory name? I'm on bash here.
37334
I've modified my .profile to include a folder if a flash drive is plugged in. When running the command as the user it works fine but tells me the scrip must be run by sudo (this is what i want). However, when i try to run it with sudo i get "command not found"  I have a symlink (flash) in my /var/www folder pointing to my /media/flash drive. (nevermind this setup since is just for dev)  this is my user's .profile :   # set PATH so it includes flash scripts if [ -d "/var/www/flash/scripts" ] ; then     PATH="/var/www/flash/scripts:$PATH" fi   when trying to run as sudo i get:  sudo: script: command not found       any ideas?
74855
On my server I have a directory structure looking something like this:  /myproject/code   I normally have an ssh connection to the server and 'stand' in that directory:  root@machine:/myproject/code#   When I deploy a new version of my code, the code directory is removed so I'm left with:  root@machine:/myproject/code# ./run -bash: ./run: No such file or directory   And the only solution I've found is to cd out and back in:  root@machine:/myproject/code# cd ../code root@machine:/myproject/code# ./run Running...   Can I avoid this? It's a somewhat strange behavior. If you have a nice explanation why this happens I would appreciate it.
103444
I've added the line   alias ll='ls -l'   to the /etc/bash.bashrc. After a restart, the alias ll from that file affects me, which I checked by commenting out the corresponding alias in my ~/.bashrc (and logging out and back in after that edit). However, it seems to not affect root, as when I type sudo ll, I get "no such command". Shouldn't the alias work in any situation if it's in the system-wide .bashrc?
34636
I want to make a shell alias that starts a certain program and also changes the title of the terminal to the name of the program.  How can I do that?  In case it matters, I am running the terminal on Ubuntu and connecting to a Debian server via ssh.
91369
The way you would normally include a script is with "source"  eg:  main.sh:  #!/bin/bash  source incl.sh  echo "The main script"   incl.sh:  echo "The included script"   The output of executing "./main.sh" is:  The included script The main script   ... Now, if you attempt to execute that shell script from another location, it can't find the include unless it's in your path.  What's a good way to ensure that your script can find the include script, especially if for instance, the script needs to be portable?
11926
I'm trying to set an alias for sudo !! in Bash. I tried alias sbb='sudo !!', but it interprets that as a literal  !! and prints   sudo: !!: command not found   If I use double quotes, it substitutes the double bang in the string itself, so that doesn't work.  Is there any way to make this work? Or an alternative alias? `
54667
I just wanted to ask whether there is any command which would work on common shells (bash, dash, kornshell)? It is supposed to check if the line variable contains any part of the path.  if [[ $line =~ "$PWD"$ ]] ;then
1635
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 starting out with Linux, I'd want to know: When to alias, when to script, and when to write a function?  Where aliases are concerned, I use aliases for very simple operations that don't take arguments.   alias houston='cd /home/username/.scripts/'   That seems obvious. But some people do this:  alias command="bash bashscriptname"   (and add it to the .bashrc file)   Is there a good reason to do that? I'm trying really hard, but I genuinely can't think of any circumstances in which I'd want to do that. So, if there is an edge case where that would make a difference, please answer below.  Because that's where I would just put something in my PATH and chmod +x it, which is another thing that came after years of Linux trial-and-error.  Which brings me to the next topic. For instance, I added a hidden folder (.scripts/) in the home directory to my PATH by just adding a line to my .bashrc (PATH=$PATH:/home/username/.scripts/), so anything executable in there automagically autocompletes.  If I needed to.  I don't really need that, though, do I? I would only use that for languages that are not the shell, like Python.  If it's the shell, I can just write a function inside the very same .bashrc:  funcname () {   somecommand -someARGS "$@" }   As I stated, I found a lot of this out through trial and error. And I only truly saw the beauty of functions when my computer died and I was forced to use the computers of the people around me when they weren't using them.   Instead of moving a whole directory of scripts from computer to computer, I ended up just replacing everyone else's .bashrc with my own, since they had never even made a single modification.  But did I miss anything?   So, what would you tell a beginning Linux user about when to alias, when to script, and when to write a function?   If it's not obvious, I'm assuming the people who answer this will make use of all three options. If you only use aliases, or only use scripts, or only use functions—or if you only use aliases and scripts or aliases and functions or scripts and functions—this question isn't really aimed at you.
47349
Sometimes when I simply type a valid command like 'find ...', or anything really, I get back the following, which is completely unexpected and confusing (... is command name I type): sh: $'\302\211...': command not found  There is some corruption going on I think. I don't use color in my prompt, I am using the Bash shell in POSIX mode as sh (chsh to /bin/sh and so on - $SHELL is sh). What is going on and why does this keep happening? Anything I can debug? I think this is more of an xterm issue than sh, or at least a combination of the two. Files, for context: My /etc/profile, as distributed with Arch Linux x86-64: # /etc/profile  #Set our umask umask 022  # Set our default path PATH=&quot;/usr/local/sbin:/usr/local/bin:/usr/bin&quot; export PATH  # Load profiles from /etc/profile.d if test -d /etc/profile.d/; then         for profile in /etc/profile.d/*.sh; do                 test -r &quot;$profile&quot; &amp;&amp; . &quot;$profile&quot;         done         unset profile fi  # Source global bash config if test &quot;$PS1&quot; &amp;&amp; test &quot;$BASH&quot; &amp;&amp; test -r /etc/bash.bashrc; then         . /etc/bash.bashrc fi  # Termcap is outdated, old, and crusty, kill it. unset TERMCAP  # Man is much better than us at figuring this out unset MANPATH  My /etc/shrc follows below. It's something I created as a way to have sh parse some file on startup, for a non-login shell; it is achieved using ENV variable set in /etc/environment with the line ENV=/etc/shrc: PS1='\u@\H \w \$ ' alias ls='ls -F --color' alias grep='grep -i --color' [ -f ~/.shrc ] &amp;&amp; . ~/.shrc  My ~/.profile, I am launching X when logging in through first virtual tty: [[ -z $DISPLAY &amp;&amp; $XDG_VTNR -eq 1 ]] &amp;&amp; exec xinit -- -dpi 111  My ~/.xinitc, as you can see I am using the system as a Virtual Box guest: xrdb -merge ~/.Xresources  VBoxClient-all  awesome &amp;  exec xterm  And finally, my ~/.Xresources, no fancy stuff here I guess: *faceName: Inconsolata *faceSize: 10 xterm*VT100*translations: #override &lt;Btn1Up&gt;: select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0)  xterm*colorBDMode: true xterm*colorBD: #ff8000 xterm*cursorColor: S_red  Since ~/.profile references among other things /etc/bash.bashrc, here is its content: # # /etc/bash.bashrc #  # If not running interactively, don't do anything [[ $- != *i* ]] &amp;&amp; return  PS1='[\u@\h \W]\$ ' PS2='&gt; ' PS3='&gt; ' PS4='+ '  case ${TERM} in   xterm*|rxvt*|Eterm|aterm|kterm|gnome*)     PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf &quot;\033]0;%s@%s:%s\007&quot; &quot;${USER}&quot; &quot;${HOSTNAME%%.*}&quot; &quot;${PWD/#$HOME/~}&quot;'                                                              ;;   screen)     PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }'printf &quot;\033_%s@%s:%s\033\\&quot; &quot;${USER}&quot; &quot;${HOSTNAME%%.*}&quot; &quot;${PWD/#$HOME/~}&quot;'     ;; esac  [ -r /usr/share/bash-completion/bash_completion   ] &amp;&amp; . /usr/share/bash-completion/bash_completion  I have no idea what that case statement does, by the way, it does look a bit suspicious though, but then again, who am I to know.
94265
I have an executable file mpiexec, whose full path is ~/petsc-3.2-p6/petsc-arch/bin/mpiexec.  Since I want to execute this command in different directories (without having to retype the entire path), I setup an alias in my home .bashrc file:    alias petsc="~/petsc-3.2-p6/petsc-arch/bin/mpiexec"     which allows me to execute this mpiexec file at the command prompt easily by typing:    petsc myexecutable   I tried to write a shell script file, named script, using my new alias petsc as a command.  After giving my shell script the appropriate permissions (using chmod), I tried to run the script.  However, it gave me the following error:    ./script: line 1: petsc: command not found   I know that I could just write the full path to the mpiexec file, but it is cumbersome to write the full path everytime that I want to write a new script.  Is there a way that I can use my alias petsc inside the script file?  Is there a way I can edit my .bashrc or .bash_profile to make this happen?
57053
If a run the watch command containing an alias, it will not expand the alias. I have tried both with single quote and double quotes, in fact given the following alias:  # alias ll alias ll='ls -l --color=tty'   The following command will fail  # watch ll sh: ll: command not found   Shouldn't command line expansion work in this case?
61254
Suppose I have an alias in the bash shell. Is there a simple command to print out what command the alias will run?
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?