Zsh function does not terminate when ${name:?word} fails


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zsh function does not terminate when ${name:?word} fails
# 1  
Old 09-07-2016
Question Zsh function does not terminate when ${name:?word} fails

(Simplified example):

I have in my .zshrc the following function definition:

Code:
function foo {
    local p=${1:?parameter missing}
    echo continue ....
}

Running the function with just foo produces, as expected, the message parameter missing, but it also output continue. I had expected that the function terminates, when the :? check fails, but it continues to run. Why is this the case?

The man-page zshexpn says:

... otherwise, print word and exit from the shell. Interactive shells instead return to the prompt.

ADDITIONAL FINDINGS:

I found that this behaviour depends on the presence of the local command. If I remove local, the function works as expected. Since I need local, I can rewrite the function like this:

Code:
function foo {
    : ${1:?parameter missing}
    local p=$1
    echo continue ....
}

This works fine, but I still am curious to know, why the presence of local causes this difference in behaviour.

UPDATE: The issue can be considered solved. Zsh developers confirmed that this behaviour is a bug in Zsh which is going to be fixed. See also Zsh function does not terminate when ${name:?word} fails - Stack Overflow

Last edited by rovf; 09-14-2016 at 08:25 AM.. Reason: Additional findings
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script fails with "function: not found" error

Hello everyone, I am having problems figuring this out. This script below is supposed to create a list of file names with their "md5sum", in a file "lib-list.txt" When I run it "sh component-list.sh " I get this:component-list.sh: 4: component-list.sh: function: not found component-list.sh:... (4 Replies)
Discussion started by: joemb
4 Replies

2. Programming

Recursion function (Anagramming word)

Sorry for my english Hello all my friends and seniors, i had created a programm in c++ (anagrammig of word) it works fine but i cannot understand how exactly recursion is working , i mean oh.. first look at the code . #include <iostream> #include <string> ... (1 Reply)
Discussion started by: rink
1 Replies

3. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

4. UNIX for Dummies Questions & Answers

How to find function name based on word search

Hi All, I want to find out function name based on word. Here i ll give u one example I have several files based on below format. file will start and ends with same name only EX: file1.txt public function calculate1() { ---- ---- call Global Function1() ---- ---- } END... (9 Replies)
Discussion started by: spc432
9 Replies

5. AIX

POLL function fails under AIX v5.3

I am having a strange problem with the poll() routine. I compiled a module under AIX 5.2 using the poll routine, it worked fine. When the OS was upgraded to AIX 5.3 the poll routine return an error code. Here is a summary of the code: #define MAX_EVENTS 300 long eventCount;... (0 Replies)
Discussion started by: TahirNazir
0 Replies

6. Programming

command to terminate

hi all how to terminate command eecution process. can you please show me the way thank you (2 Replies)
Discussion started by: munna_dude
2 Replies

7. Shell Programming and Scripting

Terminate process

We have a system user "oracle_usr" always run some process in the system , but sometimes , these processes will not stop automatically until we terminate the process , can suggest the method how to terminate the process that is run by "oracle_usr" and run over 10 minutes ? thx (5 Replies)
Discussion started by: ust
5 Replies

8. Shell Programming and Scripting

terminate process

I want to have a script to terminate the system process that generated by user oracle_usr and have already processed for over 10 minutes , could suggest the script ? thx (1 Reply)
Discussion started by: ust
1 Replies

9. Shell Programming and Scripting

terminate the process

In my system , there are a system user "cronusr" , it is mainly to run the crontab job in the database .Sometimes the cronjob process will be failure ( due to some reason ) so that many cronusr process are in the system , it affect other process in the system , I want to have a script that can... (2 Replies)
Discussion started by: ust
2 Replies

10. Shell Programming and Scripting

How to terminate a tail -f

I am developing a script with a tail -f in it. My problem is how to terminate it and execute the next line. (4 Replies)
Discussion started by: DonVince
4 Replies
Login or Register to Ask a Question