Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-22
11
Medium Priority
?
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

721 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