Reputation: 147
I have a Perl script below and I want to convert it to a Bash script but sad to say I have difficulties in Bash. Can anyone help me this.
#!/usr/bin/perl
use strict;
use warnings;
my $output = `df -h`;
my $bundle = "`awk -F \'=\' \'{print \$2}\' config.txt`";
my $bundlename = `echo $bundle | awk -F \'/\' \'{print \$11}\'`;
print $output;
system ("wget $bundle");
print "$bundlename\n";
tar();
sub tar {
my $cd = system ("tar -xzvf $bundlename") ;
system ("rm -vf $bundlename");
}
Please can anyone convert it to Bash script?
Upvotes: 0
Views: 2798
Reputation: 753970
This is a very straight-forward direct transliteration of the Perl:
#!/bin/bash
output=$(df -h)
bundle=$(awk -F = '{print $2}' config.txt)
bundlename=$(echo $bundle | awk -F / '{print $11}') # Possible echo "$bundle" instead?
echo "$output"
wget $bundle
echo "$bundlename"
tar -xzvf "$bundlename"
rm -vf "$bundlename"
Given what you do with the $output
variable, you might as well simply write:
bundle=$(awk -F = '{print $2}' config.txt)
bundlename=$(echo $bundle | awk -F / '{print $11}') # Possible echo "$bundle" instead?
df -h
wget $bundle
echo "$bundlename"
tar -xzvf "$bundlename"
rm -vf "$bundlename"
It isn't clear that the df -h
is providing any benefit to the script; you might simply delete the line instead.
Upvotes: 1
Reputation: 1
#!/bin/sh
bundle=$(awk '$0=$2' FS== config.txt)
bundlename=$(awk '$0=$11' FS=/ <<< "$bundle")
dh -h
wget $bundle
echo $bundlename
tar -xzvf $bundlename
rm -vf $bundlename
Upvotes: 2