Why would this script work with bash on Kali, but not with bash on Xubuntu?

I have a script that I made when I was at home on a Kali virtual machine. It works perfectly there, but now I’m at work on my Xubuntu install and it’s not working at all. The exact shell that I’m using via the help command is GNU bash version 4.2.25. I’m not sure what shell I have at home (assume it’s the latest version). I’m assuming that the shell I have here at work is older and therefore doesn’t support some of the things I’m using in the script? When I run it here it prints out the header and footer but nothing in between. Any help or advice would be appreciated.

#!/bin/bash

echo ""
echo "######## WHOIS: "$1

# Whois using the inputted parameter
whois $1 |

# Remove EOL characters
tr -d '1532' |

# Remove spaces
sed 's/^ *//' |

# Remove unnecessary words from output
grep -v -e "@" -e "http://" -e "WHOIS" > temp.txt

# Display all of the date lines
egrep -i "ate: " temp.txt

# Remove the tmp file
rm -rf temp.txt

echo "------- DONE!"
echo ""

Answer

Your comments and blank lines are destroying the pipe connectivity. Use this:

#!/bin/bash

echo ""
echo "######## WHOIS: "$1

whois $1 |
tr -d '1532' |
sed 's/^ *//' |
grep -v -e "@" -e "http://" -e "WHOIS" |
egrep -i "ate: " 

echo "------- DONE!"
echo ""

You don’t need a line continuation if the pipe is at the end of the line. If you want your comments, put them in a block above the pipeline.

Leave a Reply

Your email address will not be published. Required fields are marked *