Book and Links about Shells; and zsh question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Book and Links about Shells; and zsh question
# 1  
Old 03-20-2010
Book and Links about Shells; and zsh question

HI,
I would like to ask You about some good books or links where I can find information about shells, theoretical information.
I will be grateful if You can help me

And I have question about zsh loop

trivial script:
Code:
#!/bin/zsh
 for i in {1..100000}
 do
 echo $i;
 done

exec time is 10 sec
but for 500000 loops
exec time is 300 sec

Why for 500000 loops execution time is 300 seconds, it's only 5x 100000 loops it should be about 50 sec
In other shells it's OK
# 2  
Old 03-20-2010
1. there is not a lot of 'shell theory'. Production shops almost always choose a POSIX-compliant shell: probably one of: ksh (ksh88 ksh93 zsh) bash. The reason for this is portability.

read ISO/IEC subsection 3 ISO/IEC 9945
This tells you how shells are 'meant to be' I dunno if that is theory or not.

2.
a. terminal i/o is slow, net traffic botlenecks may also be involved
try this on two large-ish files, use different files to circumvent file caching:
Code:
time cat bigfile1 
time cat bigfile2 > somefile

b. the primary cause of loops bogging is process creation. You are executing echo.
if it is /usr/bin/echo and not the shell builtin echo, every loop execs a whole new child process. This is a huge amount of overhead.
Code:
which echo

tells you whether the echo you ran is builtin or not.


We need more information on the platform and OS to give you anything more useful
# 3  
Old 03-20-2010
When I type
Code:
which echo

it is /usr/bin/echo
Can I choose which echo would be executing ?

And why in different shells everything is OK ?
# 4  
Old 03-20-2010


---------- Post updated at 01:09 PM ----------

Actually, I just now noticed the "zsh" part of the subject, checked and saw that zsh (which I have zero experience with) does have a "which" builti-in. My apologies, jim_mcnamara, for jumping the gun. I had assumed you were referring to the common (though I don't think posix standardized) which(1) executable found on most BSD and Linux systems.

I will leave my original post (which follows) as is, as I think it may prevent misunderstandings among those who (like me) do not use zsh.


---------- Posted at 12:35 PM ----------


Quote:
Originally Posted by jim mcnamara
Code:
which echo

tells you whether the echo you ran is builtin or not.
That's incorrect. which(1) will search $PATH directories for an executable. If it finds anything, it will always be an external executable.

Use type to see what is actually being run.

Code:
$ which echo
/bin/echo
$ type echo
echo is a shell builtin
$ type -a echo
echo is a shell builtin
echo is a tracked alias for /bin/echo

The first result from the type built-in is what the shell will actually use. There are ways to use something other than the first found option, read your shell's man page.

Also, on ksh variants, instead of type use whence (although it may have type aliased to whence -v already as a convenience):
Code:
$ ksh --version
  version         sh (AT&T Labs Research) 1993-12-28 p

$ alias type
type='whence -v'

Regards,
Alister

Last edited by alister; 03-20-2010 at 03:17 PM..
# 5  
Old 03-21-2010
Sorry for my ignorance,
and thanx for informations.

BTW.
Code:
% which echo
echo: shell built-in command
% type -a echo
echo is a shell builtin
echo is /bin/echo

# 6  
Old 03-22-2010
Which versions of zsh are you using?

Code:
print $ZSH_VERSION

I also had such experience with old zsh versions (on Solaris < 10 default distributions, for example).

Could you please also post the versions and the timings of your tests with the other shells?
# 7  
Old 03-22-2010
zsh version:
Code:
4.3.10

ksh version
Code:
Version JM 93t+ 2009-05-01

ksh
100000 loops

Code:
1.8 sec

ksh
500000 loops

Code:
9.4 sec

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Question regarding a book for C++

Hi all. A course I am has Beginning C prescribed for our C++ work, but I am wondering, is this correct? Why not Beginning C++ by the same author? We code in C++ and learn C++, when starting a project in Code::Blocks we select C++. I may just be confused. Thanks for the help. (1 Reply)
Discussion started by: AnthonyWall56
1 Replies

2. Shell Programming and Scripting

Zsh array -a vs. -A question

Inside a zsh function, I create a local array with local -a arrayname and a local associative array with local -A arrayname. I also can create an array using set, like this: set -A arrayname value1 value2 value3In this form, I can not explicitly declare that an array is associative or... (2 Replies)
Discussion started by: rovf
2 Replies

3. UNIX for Dummies Questions & Answers

Soft links question

Hello. I have some main directories. For example : /main_dir1 /main_dir2In main_dir2, I have a sub dir named sub_dir2-1 with 2 files in it ( file_2-1, file_2-2 ) /main_dir2sub_dir2-1file_2-1 file_2-2From "/main_dir1/A/B/C" I make a soft link ln -s /main_dir2/sub_dir2-1 ... (6 Replies)
Discussion started by: jcdole
6 Replies

4. UNIX for Dummies Questions & Answers

A Basic Question About Links

How can you tell if a file is linked to another file?????? Do not title posts "Urgent", etc. Per forum rules. (3 Replies)
Discussion started by: BIGGDRE10
3 Replies

5. Shell Programming and Scripting

Question regarding shells and subshells when a script is run

I have the following script running with nohup on one of my servers: #!/bin/bash #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #set log number #i=1 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ #Check if log exits, if so incrememnt log number up so we don't clobber #while... (8 Replies)
Discussion started by: DeCoTwc
8 Replies

6. UNIX for Dummies Questions & Answers

question about zsh

hi, In bash, $ bind -P | grep yank-last yank-last-arg can be found on "\M-.", "\M-_". this allows me to press ALT key and the period (.) to yank the last argument of the previous command line into the current command line. How can I get the same behavior in zsh ? Thanks ... (0 Replies)
Discussion started by: Andrewkl
0 Replies

7. UNIX for Dummies Questions & Answers

Question posting links

Hi, I do not want to violate any rules, so thought to ask before posting any links. Just to contribute to the forum: through surfing I found a link to download "Unix in a Nutshell" (*.chm) FREE. I was wondering if I can post that link here. Thanks Hemang (5 Replies)
Discussion started by: hemangjani
5 Replies

8. UNIX for Dummies Questions & Answers

A question for links in Unix

Is there a command that I can list, at once, all the links(path) of a give file ( including hard link and soft link)? If not, can it be down by writing a script? Thanks a lot. (I know that pwd would only list one path.) (2 Replies)
Discussion started by: nj302
2 Replies

9. UNIX for Dummies Questions & Answers

basic question about shells?

I have come across the topic of changing shells, does that mean that all Unix operating systems comes with a variety of shells built in and its up to the user to select a shell of his/her choice? (2 Replies)
Discussion started by: wmosley2
2 Replies
Login or Register to Ask a Question

Featured Tech Videos