Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jun 032011
 

How to echo string to standard error (stderr)?

Answer:

To echo string to the standard error (stderr), rather than the standard output (stdout), you can define the following function in your shell (put in your ~/.bashrc file)

# function echo2() { echo "$@" 1>&2; }

Then you can execute the command like:

# echo2 test

Jun 012011
 

Simple for loop in Bash shell

Answer:

A simple for loop in Bash shell would like the following. You can use it wisely to skip a lot of repetitive tasks.

#!/bin/bash

for i in {1..10}
do
   echo "I am command No. $i"
done
May 242011
 

Printing the exclamation mark using echo

Answer:

You might observed a problem when you try to print the exclamation mark (!) using the echo command

E.g.

# echo "test!"
-bash: !": event not found

To solve it, you can use single quote instead

# echo 'test!'
test!
Apr 162011
 

Remove the whole line when typing a command in Bash

Answer:

When you are typing a command in Bash shell, , to quickly remove the whole line, press "Ctrl + u" or "Ctrl + c"

This trick is very handy and should be known by all Bash users.

You might also want to read:

  1. http://www.linuxask.com/questions/moving-around-with-bash-short-cut
  2. http://www.linuxask.com/questions/remove-the-last-word-when-typing-a-command-in-bash