zsh and parallel: How to use functions. It says command not found


I have a script file

filename: test_sem_zsh.sh

main() { echo "Happy day" } export -f main sem --id testing --fg main

I am trying to run it using zsh

$ zsh test_sem_zsh.sh test_sem_zsh.sh:export:4: invalid option(s) zsh:1: command not found: main

It says two error's 1) main command not found and 2) export:4: invalid option(s)

Where as when i try with bash it works

$ sh test_sem_zsh.sh Happy day

So how to get this script working with zsh also


Not certain what you are trying to do, but this may help you define a chunk of code you can run under sem without needing bash's export:

#!/bin/zsh # Create script in /tmp script="/tmp/tmp-$$" cat <<EOF > "$script" echo "Happy day" date EOF sem --id testing --fg /bin/zsh "$script" rm "$script"

This answer is conceptual... for production use, you should set up a trap to remove the script, probably use mktemp and improve security.


sem is just a shorthand for parallel --semaphore.

You can use env_parallel:

#!/usr/bin/zsh # activate env_parallel (if not already done) . =env_parallel.zsh env_parallel --semaphore --id testing --fg main

Or if your environment is too big:

#!/usr/bin/zsh # activate env_parallel (if not already done) . =env_parallel.zsh env_parallel --session main() { echo "Happy day" } env_parallel --semaphore --id testing --fg main env_parallel --end-session



  • StreamProvider works correctly, however on stream update child widgets don't rebuild. UI not up
  • Synchronizing Spring cache based on record id
  • Login module control flag is not available in the JAAS config - Scala Kafka
  • Java装箱和拆箱
  • NullReferenceException from ViewData which is Not Null actually
  • jupyter nbconvert --to notebook not excluding raw cells
  • .net string comparison with collation
  • How to create a listview with 2 columns showing all installed android apps and the permissions along
  • do sessions work when cookies are disabled?
  • Decoding unknown Encodable enum values to a default
  • Mono for Android OnPause event not triggering on Galaxy Nexus
  • Merging Models from ModelBuilder in LibGDX
  • Elastic Search, is it possible to get the index of a specific document in a search result set?
  • Where to put dispatch.Http.shutdown()
  • Why does ng-mouseover not work with ng-if
  • boto3 S3 Object Parsing
  • scipy.signal's convolve differs from calculated result
  • Identify xml text elements with Schematron
  • Customize jQuery submenu positioning
  • Retrieving Application's DisplayName/UninstallString from Registry Using Powershell
  • Pyinstaller GLIBC_2.15 not found
  • How to add multiple legend titles (columns) in ggplot
  • the IBM_JAVA error for running jobs in Hadoop 2.2.0
  • Threads and Concurrent Modification Exception working with a list
  • Use awk to convert GPS Position to Latitude & Longitude
  • How to fetch asset modification history in hyperledger fabric
  • Unable to start a WebView from an AsyncTask
  • C# code can't “see” the methods in my C++ dll
  • Java Collections.shuffle() weird behaviour [closed]
  • All Event listing on specified date in Google Calender api (V3) in java?
  • When to use the tag in the head and body section of a html page? [duplicate]
  • How to run chrome.tabs.insertCSS from the background page on each page?
  • How to use Kaminari pagination gem with Sinatra and Mongoid?
  • Create an average of multiple excel chart without the data source
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • Google App Engine Datastore: Dealing with eventual consistency
  • ssh remote server login script
  • How to call different template for different category archive page in woocommerce
  • No OpKernel was registered to support Op 'Conv2D' with these attrs