Skip to main content
added 6 characters in body; edited tags
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

how to deal with arguments when executing a script

my code is:

#!/bin/bash

DIR="$1"

if [ DIR eq $1 ]
then
    echo -n "total directories:" ; find $DIR -type d | wc -l
    echo -n "total files:" ; find $DIR -type f | wc -l
else
    echo " pass parameters"
fi

when I executed with the script name  (./countfiledirs./countfiledirs) itsit's showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254

how to deal with arguments when executing a script

my code is:

#!/bin/bash

DIR="$1"

if [ DIR eq $1 ]
then
    echo -n "total directories:" ; find $DIR -type d | wc -l
    echo -n "total files:" ; find $DIR -type f | wc -l
else
    echo " pass parameters"
fi

when I executed with the script name(./countfiledirs) its showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254

how to deal with arguments when executing a script

my code is:

#!/bin/bash

DIR="$1"

if [ DIR eq $1 ]
then
    echo -n "total directories:" ; find $DIR -type d | wc -l
    echo -n "total files:" ; find $DIR -type f | wc -l
else
    echo " pass parameters"
fi

when I executed with the script name  (./countfiledirs) it's showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254
improve formatting
Source Link
taliezin
  • 9.5k
  • 1
  • 37
  • 39

how to deal with arguments when executing a script

my code is:

#!/bin/bash DIR="$1"

if [ DIR eq $1 ]
then

echo -n "total directories:" ; find $DIR -type d | wc -l

echo -n "total files:" ; find $DIR -type f | wc -l
 else
    echo " pass parameters"
fi
#!/bin/bash

DIR="$1"

if [ DIR eq $1 ]
then
    echo -n "total directories:" ; find $DIR -type d | wc -l
    echo -n "total files:" ; find $DIR -type f | wc -l
else
    echo " pass parameters"
fi

when I executed with the script name(./countfiledirs) its showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254

how to deal with arguments when executing a script

my code is:

#!/bin/bash DIR="$1"

if [ DIR eq $1 ]
then

echo -n "total directories:" ; find $DIR -type d | wc -l

echo -n "total files:" ; find $DIR -type f | wc -l
 else
    echo " pass parameters"
fi

when I executed with the script name(./countfiledirs) its showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254

how to deal with arguments when executing a script

my code is:

#!/bin/bash

DIR="$1"

if [ DIR eq $1 ]
then
    echo -n "total directories:" ; find $DIR -type d | wc -l
    echo -n "total files:" ; find $DIR -type f | wc -l
else
    echo " pass parameters"
fi

when I executed with the script name(./countfiledirs) its showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254
Source Link

how to deal with arguments when executing a script

how to deal with arguments when executing a script

my code is:

#!/bin/bash DIR="$1"

if [ DIR eq $1 ]
then

echo -n "total directories:" ; find $DIR -type d | wc -l

echo -n "total files:" ; find $DIR -type f | wc -l
 else
    echo " pass parameters"
fi

when I executed with the script name(./countfiledirs) its showing as:

./countfiledirs: line 4: [: DIR: unary operator expected
 pass parameters

If I execute ./countfiledirs without passing arguments it should have to show like:

pls pass arguments.

If I execute ./countfiledirs with passing arguments as ./countfiledirs /usr/share it should have to show output like:

total directories:145
total files:254