Test for Bash Bug Vulnerability CVE-2014-6271 (Shellshock)

Try this line in a Mac or Linux terminal to know if you're vulnerable nor not: env x='() { :;}; echo vulnerable' bash -c 'echo test' If you're not vulnerable, this line will just output "test", else it will output "vulnerable test". For Debian Wheezy users there's an official update available already. For those that […]

Accessing SQLite with Bash, Perl and Python

Perl: #!/usr/bin/perl -w use DBI; use strict; my $db = DBI->connect("dbi:SQLite:test.db", "", "", {RaiseError => 1, AutoCommit => 1}); $db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)"); $db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')"); my $all = $db->selectall_arrayref("SELECT * FROM n"); foreach my $row (@$all) { my ($id, $first, $last) = @$row; […]

To print the first and last characters of a string in bash

The actual string: var="somebash" This outputs "some": echo ${var:0:4} echo $var | sed 's/\(.\{4\}\).*/\1/' echo $var | awk '{print substr($0,1,4)}' echo $var | cut -c1-4 printf "%.4s\n" "$var" echo "${var%${var#????}}" This outputs "bash": echo $var | cut -c4- echo "${var#????}" echo ${var:4} echo $var | awk '{print substr($0,5)}'