My script doesn't work in the terminal window!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My script doesn't work in the terminal window!
# 15  
Old 02-22-2013
Here is the script

Code:
#!/sw64/bin/zsh

find ./ -type d -maxdepth 1 -mindepth 1 > list_of_dir.txt

sed 's/^...//' <list_of_dir.txt >list_of_dir2.txt

rm list_of_dir.txt 

echo list of data > list_of_data.txt

no_of_dir=$(wc -l < list_of_dir2.txt)

for i in {1..$no_of_dir}

do

current_dir=$(sed -n "$i"p list_of_dir2.txt)

echo "\n"$current_dir >> list_of_data.txt

cd $current_dir

ls *.jpeg | awk -F_ '{A[$1 FS $2]++} END {for (j in A) printf "%-20s%4d \n", j, A[j] >> "../list_of_data.txt"}' 

cd ..

done

yes the script is executable
# 16  
Old 02-22-2013
OK, assuming that is the right zsh path, and if not there would be an error, is '{1..$no_of_dir}' a correct expanding string? Well, I have no zsh but the zsh doc says it is OK if the variable is expanded first. If not, you need an eval or something. Your use of it seems abuse (lose things in pile and then grope for them), why not just
Code:
while read current_dir;do ... done <  list_of_dir2.txt

# 17  
Old 02-22-2013
I wonder if its not something to do with your environment... You have something there that is missing in your scripts like PATH to a different find or sed etc... because -maxdepth is not standard in solaris so I can guess you are using gnu find, and so may also have another sed than the standard...
Have a check...
# 18  
Old 02-22-2013
Hi DGPickett

I have just come across the while read (file) option and it works beautifully!

Thanks everyone for your help. although I still dont' quite understand why the for loop and sed combination didn't work.
# 19  
Old 02-22-2013
Yes, "while read" is a keeper, pipeline parallel and robust. Read can capture fields, and bash has "read -a simple_array_var_typedef_-a" so you do not even have to count or name them. I mostly use "while read a b c" where c gets the rest. I nevr use 'while read' with no vars, as I have to shift and type more for $REPLY.

One recent post noted that "for i in {1..999999999}" might make a command line too long, slowly, but "i=0; while (( ++i < 999999999 )) ; do ... done" has no such problems.
This User Gave Thanks to DGPickett For This Post:
# 20  
Old 02-22-2013
Thanks DGpickett but I have no idea what you talking about lol
# 21  
Old 02-22-2013
That's okay, I'm amazed it ever worked at all Smilie All it ever does for me is jam the value "{1..9}" into the sed statement instead of looping 1 through 9 -- and this is a shell that supports {1..9}, just not with variables in it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Toggle between xterm window and standard terminal window

Is it possible to toggle back and forth between an xterm invoked from one tty, and a shell invoked from a different tty? I am running Centos 7 with KDE and booting in non-graphic mode. After logging in on the default window (/dev/tty1) , I can then use ALT-F2 to access a new window (/dev/tty2),... (1 Reply)
Discussion started by: rhgscty
1 Replies

2. Shell Programming and Scripting

[Solved] Script doesn't work..help?

hi, i am trying to run this script.the name of script is final.sh after i run it: #./final.sh & i grep the command # ps -a | grep bash and i see more then one processes runing 3!! Please use code tags how can i solve this problem? my target script must always run in... (8 Replies)
Discussion started by: zigizag
8 Replies

3. UNIX for Dummies Questions & Answers

Script run everytime a new terminal window is opened

I created a script called title #!/bin/sh echo "^0;$*^G" It will change the terminal window titlebar to what ever I type after the script (title BIG would change titlebar to BIG instead of terminal) Is there a way to make it run so it will work on every terminal window that gets opened.... (1 Reply)
Discussion started by: amason0508
1 Replies

4. Shell Programming and Scripting

my script doesn't work :(

i have this script and when i ejecute it, the console tell me this " sintax error line 41 unexpected element "}" " is the sintaxis ok? #!/bin/bash if ;then { exit 0; } if ; then { sudo /etc/init.d/apache2 start; sudo /etc/init.d/mysql start; php5 & nautilus... (3 Replies)
Discussion started by: keiserx
3 Replies

5. Shell Programming and Scripting

Script doesn't work in loop but does if not

I have a script that only works if I remove it from the looping scenario. #!/bin/bash # Set the field seperator to a newline ##IFS=" ##" # Loop through the file ##for line in `cat nlist.txt`;do # put the line into a variable. ##dbuser=$line echo "copying plugin..." ... (6 Replies)
Discussion started by: bugeye
6 Replies

6. Shell Programming and Scripting

two grep in one script doesn't work?

Hi there, the following script doesn't work. the first part works, then the second 'grep' fails with ': not found'. However, if I take out the second part (starting with the grep command) and put in a seperate script, it works. everyone know what's wrong here? no two 'grep' in one script, that... (2 Replies)
Discussion started by: monkey77
2 Replies

7. Shell Programming and Scripting

Help with script.. it Just doesn't work

Hello,, Im verry new to scripting and have some problems with this script i made.. What it does: It checks a directory for a new directory and then issues a couple of commands. checks sfv - not doing right now checks rar - it checks if theres a rar file and when there is it skips to... (1 Reply)
Discussion started by: atmosroll
1 Replies

8. Shell Programming and Scripting

gcd.sh script doesn't work...

Hi there. I'm new to scripting in bash shell and I have this problem. I'm trying to make a script that returns the greatest common divisor of two integer numbers according to Euclid's algorithm... Here is, what I've done: #!/bin/bash m=$1 n=$2 while do if ; #line 8 then m=$m-$n... (1 Reply)
Discussion started by: kantze
1 Replies

9. UNIX for Dummies Questions & Answers

Script doesn't work, but commands inside work

Howdie everyone... I have a shell script RemoveFiles.sh Inside this file, it only has two commands as below: rm -f ../../reportToday/temp/* rm -f ../../report/* My problem is that when i execute this script, nothing happened. Files remained unremoved. I don't see any error message as it... (2 Replies)
Discussion started by: cheongww
2 Replies

10. Solaris

Script to launch terminal window?

Hi, I am a newbie here. Trying to find a way of writing a script to launch multiple terminal or console windows on solaris 9. I used to be able to do this using cmdtool on older versions of solaris and it was even possible to configure the size and screen position of the window and the title. ... (5 Replies)
Discussion started by: omerta
5 Replies
Login or Register to Ask a Question