Solved

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

Posted on 2007-11-22
11
306 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

770 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