Solved

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

Posted on 2007-11-22
11
309 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

860 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