Solved

wtf??  can't get my arrays to werk!!

Posted on 2007-11-22
11
297 Views
Last Modified: 2013-12-26
here is the first bit of my script:

export i=0
export j=0
declare -a pkg
pkg[1]="fuh1"
echo "pkg 1 is ${pkg[1]}"
echo "1 is $1"
rm file 2> /dev/null
ls $1 > file
ls $1 | while read file; do
echo "1 is $1"
 echo "i is $i j is $j"
 echo "file is $file"
 pkg[$((i))]="$file"
 echo "pkg 0 is $pkg[0]"
 i=$((i+1))
 if [ $((i%8)) -eq 0 ]; then
   j=$((j+1))
   echo "j is $j"
   gzip "${1}/${1}${j}.zip" "${1}/${pkg[0]}" "${1}/${pkg[1]}" "${1}/${pkg[2]}" "
${1}/${pkg[3]}" "${1}/${pkg[4]}" "${1}/${pkg[5]}" "${1}/${pkg[6]}" "${1}/${pkg[7
]}" >/dev/null


it's called the "zipix" script.

can't seem to make the pkg array do what i want it to

pkg[1]=fuh1: not found
./zipix: 5: Syntax error: Bad substitution
# ./zipix 100olymp/
declare: not found
pkg[1]=fuh1: not found
./zipix: 5: Syntax error: Bad substitution
#

just changed it:
export i=0
export j=0
declare -a pkg
rm file 2> /dev/null
ls $1 > file
ls $1 | while read file; do
echo "1 is $1"
 echo "i is $i j is $j"
 echo "file is $file"
 pkg[$((i))]="$file"
 echo "pkg 0 is $pkg[0]"
 i=$((i+1))
 if [ $((i%8)) -eq 0 ]; then
   j=$((j+1))
   echo "j is $j"
   gzip "${1}/${1}${j}.zip" "${1}/${pkg[0]}" "${1}/${pkg[1]}" "${1}/${pkg[2]}" "
${1}/${pkg[3]}" "${1}/${pkg[4]}" "${1}/${pkg[5]}" "${1}/${pkg[6]}" "${1}/${pkg[7
]}" >/dev/null
 fi
./zipix: 5: Syntax error: Bad substitution
# ./zipix 100olymp/
declare: not found
./zipix: 16: Syntax error: Bad substitution
#

line 16 is that garanguan gzip command.  this script was werking on cygwin.. but now my winders is
shot i have freeBSD gnome

0
Comment
Question by:kayvey
  • 9
  • 2
11 Comments
 

Author Comment

by:kayvey
ID: 20336840
ls $1 | while read file; do
echo "1 is $1"
 echo "i is $i j is $j"
 echo "file is $file"
 pkg[$((i))]="$file"
 echo "pkg 0 is $pkg[0]"
 i=$((i+1))
 if [ $((i%8)) -eq 0 ]; then
   j=$((j+1))
   echo "j is $j"
   gzip "${1}/${1}${j}.zip" "${1}/${pkg[0]}" "${1}/${pkg[1]}" "${1}/${pkg[2]}" "
${1}/${pkg[3]}" "${1}/${pkg[4]}" "${1}/${pkg[5]}" "${1}/${pkg[6]}" "${1}/${pkg[7
]}" >/dev/null
 fi
done < (ls $1)
0
 

Author Comment

by:kayvey
ID: 20336841
i might be doing zsh now.  i switched back and forth zsh bash.  maybe i should try ksh now
0
 

Author Comment

by:kayvey
ID: 20336843
# pkg_add -r ksh
Error: FTP Unable to get ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/ksh.tbz: File unavailable (e.g., file not found, no access)
pkg_add: unable to fetch 'ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6.2-release/Latest/ksh.tbz' by URL
# find /usr/ports -name ksh
#


oh dear.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 20336957
Are you doing this as a learning exercise or are you trying to address an actual problem?  If the latter, then there is rarely a need to use arrays in shell scripts as there are generally better ways of approaching the problem.
0
 

Author Comment

by:kayvey
ID: 20337052
this script used to werk.  if you think you have a "better" solution that will force me to rewerk the whole thing i will prolly do it notheless.

IT SHOULD WERK!  IT DOESN"T!!!!!!!!!  it werks on cygwin
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 20337077
You'd get those errors if you weren't running it under bash.

Do you have

#!/usr/bin/bash

or

#!/usr/local/bin/bash

as the very first line of the script?

Also, what does your script actually do?
0
 

Author Comment

by:kayvey
ID: 20337095
i know i am under bash but i will show you...

# which bash
/usr/local/bin/bash
#

and i tried that already

or maybe i didn't

*#&*@#
0
 

Author Comment

by:kayvey
ID: 20337098
i THOUGHT i tried that

#!/usr/local/bin/bash
export i=0
export j=0
declare -a pkg
rm file 2> /dev/null
ls $1 > file
ls $1 | while read file; do
echo "1 is $1"
 echo "i is $i j is $j"
 echo "file is $file"
 pkg[$((i))]="$file"
 echo "pkg 0 is $pkg[0]"
 i=$((i+1))
 if [ $((i%8)) -eq 0 ]; then
   j=$((j+1))
   echo "j is $j"
   gzip "${1}/${1}${j}.zip" "${1}/${pkg[0]}" "${1}/${pkg[1]}" "${1}/${pkg[2]}" "
${1}/${pkg[3]}" "${1}/

/usr/local/bin/bash
# ./zipix 100olymp/
./zipix: line 19: syntax error near unexpected token `('
./zipix: line 19: `done < (ls $1) '
#







0
 

Author Comment

by:kayvey
ID: 20337099
*&$*$
0
 

Author Comment

by:kayvey
ID: 20337117
okay i mucked up my script with some garbly i feel real stupid but you get the points.

i tried the shebang line.. seriously
0
 

Author Comment

by:kayvey
ID: 20337128
100olymp/
i is 152 j is 19
file is pb220160.jpg
pkg 0 is pb220001.jpg[0]
1 is 100olymp/
i is 153 j is 19
file is pb220161.jpg
pkg 0 is pb220001.jpg[0]
1 is 100olymp/
i is 154 j is 19
file is pb220162.jpg
pkg 0 is pb220001.jpg[0]
1 is 100olymp/
i is 155 j is 19
file is pb220163.jpg
pkg 0 is pb220001.jpg[0]
100olymp//100olymp/20.zip: No such file or directory
100olymp//pb220001.jpg: No such file or directory
100olymp//pb220002.jpg: No such file or directory
100olymp//pb220003.jpg: No such file or directory
100olymp//pb220004.jpg: No such file or directory
156 pix are zipped
there are 20 zipfiles
#

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now