Solved

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

Posted on 2007-11-22
11
316 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Suggested Courses

634 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