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.

Mar 282011
 

Swap last two characters in Bash

Answer:

Sometimes it is easy to mis-type characters in the wrong order, e.g. typed "sl" instead of "ls"

To swap it, use the little know Bash's trick: Ctrl + t

E.g.

# sl 
[Ctrl + t]
Sep 112010
 

Multi-line strings in Bash

Answer:

Bash support multiple line string, e.g.

#!/bin/bash
sort  <<EOT
apple
orange
banna
EOT

When you execute the script,

# bash test.sh

It gives:

apple
banna
orange
May 302010
 

How to perform syntax check on a bash script?

Answer:

You can perform syntax check on a bash script, without actually running it using the following command:

# bash -n script.sh

But if your script contain execution of other program, bash will not try to run it, even if it does not exist, error of this type will not be returned.