All posts tagged bash

$# : Number of arguments passed via script

$0 : Name of the script

$@ : Names of arguments passed to the script at execution

$$ : Process ID associated with script

$OSTYPE : What’s the OS type?

$TERM :  What’s term is being used?

$USER : What’s the username that executed the script?

$HOSTNAME : What’s the hostname of the box that ran the script?

$LOGNAME :  What was the login username?

$LINENO : Current line # of the script

$RANDOM : Random #

$BASH_SOURCE :  What’s the bash source?

Example script:





This typically happens if the files (ie pictures) originated from a Windows host.  I’ve found it’s much easier to just remove the spaces in the files than to deal with trying to properly quote your escapes in your loops.  

All words only.

All words and digits

Sometimes piping to less on each is helpful depending on how big your file is.

So recently I updated my bash prompt to be a little easier on my eyes, however, after I was done for some reason if I typed in long commands they would not automatically wrap to the next line, it would just overwrite the current line. This made things a little interesting..hah

Here’s my new prompt, (which had the problem..)

export PS1="\e[32m[\@] \u@\h:\e[33m\w \e[32m\$ "

[11:16 PM] phatdee@thebeaver:/tmp $

To fix this, you need to do this, you need to wrap each escape section using [\  \]. This is needed so that readline will be able to correctly evaluate the where the margin ends thus automatically switching to the new line and not just writting over the same line. I’m sure this can be explained a little better but hopefully you get it. Here’s the working PS1 line, pay special attention to the 4 new [\ \] , two for each escape (\e) section.
Also instead of switching to the “green” color in the above which is escape 32m, I just reset the color back to the original to do that, just use \e[0m

export PS1="[\@] \u@\h:\[\e[1;33m\]\w\[\e[0m\] $ "

[12:24 AM] phatdee@thebeaver:/var/tmp $


Some syntax help:

\@ = does the time in 12H mode

\u = username of logged in user ($LOGNAME)

\h = hostname

\w = current directory

\e[1;33m = yellow text

\e[0m = resets text to original


I use terminator for my terminal client, and often have multiple windows open with different sizes.  I was finding that sometimes my window would not word wrap no matter what I did.  However after turning this on, I no longer had that issue.

$ shopt | grep checkwinsize

If this is off, try turning this on

$ shopt -s checkwinsize

Add this to your .bashrc if you find it working.

Renaming/moving files with suffixes quickly:

This expands to:

cd ESC.