this script does not work

I have this script
Code:
#!/bin/sh
CAP=4000000000
SIZEARR=(`ls -l |awk '{if(NR > 1) {print $5}}'`)
NAMEARR=(`ls -l |awk '{if(NR > 1) {print $8}}'`)
NUMELS=${#NAMEARR[@]}
NUMDIR=0
let N=$CAP+1
for (( i=0;i<$NUMELS;i++))
do
    if [ $N -gt $CAP ]
    then
        let NUMDIR++
        CURDIR="Dir$NUMDIR"
        mkdir $CURDIR
        let N=0
    fi
    let N=$N+${SIZEARR[${i}]}
    cp ${NAMEARR[${i}]} $CURDIR
done
but when I run it with this command
Code:
sh 4gb
I see this error
Code:
4gb: 1: Syntax error: word unexpected (expecting ")")
I test this script in Fedora and it work good
 
mfaridi said:
I have this script

I test this script in Fedora and it work good

Linux's 'sh' = 'bash'. Either rewrite it in true sh syntax, or run it with
Code:
#!/usr/local/bin/bash
.
 
Back
Top