HiliteJs Demo: Linux / Unix Scripting


Shell Script - Bash

#!/bin/bash

###### CONFIG
ACCEPTED_HOSTS="/root/.hag_accepted.conf"
BE_VERBOSE=false

if [ "$UID" -ne 0 ]
then
 echo "Superuser rights required"
 exit 2
fi

genApacheConf(){
 echo -e "# Host ${HOME_DIR}$1/$2 :"
}

Shell Session

$ echo $EDITOR
vim
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ git push
Everything up-to-date
$ echo 'All
> done!'
All
done!

Perl

use strict;

#
# This script demonstrates some of the properties of
# array assignments.
#
my @a = ("Small", "Medium", "Large");
print `@a = ` . "@a\n";

my ($smith, $jones, $johnson) = @a;
print "$smith $jones $johnson\n";

my ($here, $there) = @a;
print "$here $there\n";

my ($this) = @a;
print "$this\n";

my $this = @a;
print "$this\n";

my ($p, $q, $r, $s, $t) = ("p", "q", "r", "s", "t");
print "[$p] [$q] [$r] [$s] [$t]\n";
($p, $q, $r, $s, $t) = @a;
print "[$p] [$q] [$r] [$s] [$t]\n";

# A cute way to swap variables.
my $aa = "Fred";
my $bb = "Barney";
($aa, $bb) = ($bb, $aa);
print "$aa $bb\n";