Post Closed as "duplicate" by muru, Romeo Ninov, G-Man, schily, slm bash of
2 added 72 characters in body
source | link

So I'm writing a simple script that checks if the size of the file is less than the given argument and if its true then its suppose to echo "YES"

#!bin/bash

Function ()
{
    cd $1
    lista=`ls`
    for item in $lista
    do
        if [ ! -d $item ]
        then
            size=`wc -c $item | awk '{ print $1 }'`
            if [ $size -lt $2 ]
            then
                echo "$item"
            fi
        else
            Function $item $2
        fi
        cd ..
    done
}

Function $1 $2

And the bash:

bash test2.sh /home/161161 300

However something is wrong with the wc -c because it gives me the error that no such file or exist after running through the second loop.

Any ideas?

So I'm writing a simple script that checks if the size of the file is less than the given argument and if its true then its suppose to echo "YES"

#!bin/bash

Function ()
{
    cd $1
    lista=`ls`
    for item in $lista
    do
    if [ ! -d $item ]
    then
    size=`wc -c $item | awk '{ print $1 }'`
    if [ $size -lt $2 ]
    then
    echo "$item"
    fi
    else
    Function $item $2
    fi
    cd ..
    done
}

Function $1 $2

And the bash:

bash test2.sh /home/161161 300

However something is wrong with the wc -c because it gives me the error that no such file or exist after running through the second loop.

Any ideas?

So I'm writing a simple script that checks if the size of the file is less than the given argument and if its true then its suppose to echo "YES"

#!bin/bash

Function ()
{
    cd $1
    lista=`ls`
    for item in $lista
    do
        if [ ! -d $item ]
        then
            size=`wc -c $item | awk '{ print $1 }'`
            if [ $size -lt $2 ]
            then
                echo "$item"
            fi
        else
            Function $item $2
        fi
        cd ..
    done
}

Function $1 $2

And the bash:

bash test2.sh /home/161161 300

However something is wrong with the wc -c because it gives me the error that no such file or exist after running through the second loop.

Any ideas?

1
source | link

wc -c not working in a loop in the script

So I'm writing a simple script that checks if the size of the file is less than the given argument and if its true then its suppose to echo "YES"

#!bin/bash

Function ()
{
    cd $1
    lista=`ls`
    for item in $lista
    do
    if [ ! -d $item ]
    then
    size=`wc -c $item | awk '{ print $1 }'`
    if [ $size -lt $2 ]
    then
    echo "$item"
    fi
    else
    Function $item $2
    fi
    cd ..
    done
}

Function $1 $2

And the bash:

bash test2.sh /home/161161 300

However something is wrong with the wc -c because it gives me the error that no such file or exist after running through the second loop.

Any ideas?