Too Many Arguments Error - shells script

Hi,

I am getting the below error

: [: too many arguments error at the if condition start and when I print the

value of TEST, it displays two values as below

/home/xyz/out/file1.txt 
/home/xyz/out/file2.txt
if [ -f $TEST]; then
    mv $TEST $TARGETDIR/    
fi

Tried by enclosing it in double quotes "$TEST", but it doesnt enter into the if condition.

Please help on this.

Use a for loop to visit each values in variable: TEST

for file in $TEST
do
        if [ -f "$file" ]
        then
                mv "$file" "${TARGETDIR}/"
        fi
done

Your code says:

if [ -f $TEST]; then

It should be:

if [ -f $TEST ]; then

There has to be a space before the ]

Thanks for the Resolution. It worked :slight_smile:

Yes, the [ ] is very picky about having that space there.