--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+$|=1;
+
+my $TABLE = 'shell_function';
+my $q = chr(39);
+
+print ''
+ ."SELECT 'Update shell_function';\n"
+ ."DROP TABLE IF EXISTS $TABLE;\n"
+ ."CREATE TABLE $TABLE (name VARCHAR(255) PRIMARY KEY,code BLOB);\n"
+ ."BEGIN TRANSACTION;\n"
+;
+END { print "COMMIT;\n"; }
+
+#@ARGV = ("bash --login -c 'for f in `shell_functions`; do type \$f || continue; done' |");
+@ARGV = ("bash -norc -c 'for i in $ENV{NB_ROOT}/etc/profile.d/*; do . \$i; done; for f in `shell_functions`; do type \$f || continue; done' |");
+$? and die;
+my @fct = ( '', () );
+while ( <> ) {
+
+ if (/^(\S+) is a function$/) {
+ sql(@fct);
+ @fct = ( $1, () );
+ next;
+ }
+
+ next unless $fct[0];
+ push @{$fct[1]}, $_;
+
+}
+sql(@fct);
+
+exit 0;
+
+sub sql {
+ #use Data::Dumper; print Dumper(\@_),"\n"; return;
+ return if !@_ or !$_[0];
+ my $k = $_[0];
+ my $v = join('',map {
+ s/$q/$q.$q/ge; $_
+ } @{ $_[1] });
+ print qq|INSERT INTO $TABLE VALUES ($q$k$q,$q$v$q);\n|;
+ return;
+
+ while (@{ $_[1] }) {
+ my $k = shift @{ $_[1] };
+ next unless $k;
+
+ my $v = shift @{ $_[1] };
+ $v =~ s/$q/$q.$q/ge;
+
+ #print qq|INSERT INTO $t VALUES ($q$k$q,$q$v$q);\n|;
+ }
+}