mercredi 28 septembre 2016

Checking input with an if statement (bash)

I am trying to write a file that mimics the cat -n bash command. It is supposed to accept a filename as input and if no input is given print a usage statement.

This is what I have so far but I am not sure what I am doing wrong:

#!/bin/bash
echo "OK"
read filename
if [ $filename -eq 0 ]
then 
    echo "Usage: cat-n.sh file"
else
    cat -n $filename
fi

Aucun commentaire:

Enregistrer un commentaire