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.

Repeat previous command in Bash

Answer:

It is easy to type !! when you want to repeat the previous executed command in Bash

# ls -l /var/log/messages
-rw-r----- 1 syslog adm 330 Mar 29 17:17 /var/log/messages

# !!
ls -l /var/log/messages
-rw-r----- 1 syslog adm 330 Mar 29 17:17 /var/log/messages

How to unset an environment variable in bash

Answer:

To unset an environment variable in bash, you can use the unset command.

Example:

# export foo=bar
# echo $foo
bar
# unset foo
# echo $foo

How to check the bash shell version

Answer:

To check the current bash shell version

# bash -version
GNU bash, version 3.2.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.

How to execute a command repeatedly using bash

Answer:

The following simple bash script will run the echo command, sleep 10 seconds repeatedly.

#!/bin/bash 

while [1];
do
    echo "Hello!";
    sleep 10;
done

How to get the PID in current bash shell script

Answer:

Use the special variable $$, you can get the PID (Process ID) of the current bash shell script

#/bin/bash

echo $$;

The above script will print the PID to the standard out.