0

Running the script in-theory should output results per line depending on the arguments used

The scripts name is 'stdout', and have made it exacutable. I enter './stdout GOOGLE.COM' into the console and nothing happens

#!/bin/bash

if [ $# -lt 1 ]; then
        echo "Results: [ cat whois_google.com.txt | grep $1 | cut -d ' ' -f 3 | sort -r]"
        exit 1
fi

There are no errors, the text file is a dummy file including simple fields such as 'Server Name: GOOGLE.COM.AR' and after running the command I'm hoping for an output of the different server names

Cyrus
  • 84,225
  • 14
  • 89
  • 153
  • Replace `[ cat ...]` with `$( cat ...)`. – Cyrus Oct 24 '19 at 18:42
  • 1
    you have `[ $# -lt 1 ]`, you should have something other than `-lt`. Maybe `-ge` or `-eq`? Once you're getting the expected `echo`, you can follow @Cyrus's correction to actually execute the subshell. – erik258 Oct 24 '19 at 18:44
  • You really [don't need `cat` here at all.](/questions/11710552/useless-use-of-cat) – tripleee Oct 24 '19 at 19:01
  • 2
    `exit 1` is usually an indication that there was an error. You want `exit 0` or just let the script run to its end, which returns the status code of the last external command which the script executed. – tripleee Oct 24 '19 at 19:03

1 Answers1

0

if you pass an argument to your script it will never do anything... the if [ $# -gt 0 ]; then line of script is checking to see if the number of arguments is less than 1. Try changing to -gt. Also a bad idea to call your script stdout, pick a name for what your script does.

cyber-monk
  • 5,470
  • 6
  • 33
  • 42
  • 1
    Probably `-ge`, not? With `-gt`, it'll only work if there are 2 or more arguments. Alternatively, `if (( $# ))` is true for 1 or more arguments, false for 0. – Benjamin W. Oct 24 '19 at 20:25