You are not logged in.

#1 2012-11-22 20:28:43

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,454
Website

Using 'export -f FUNCTION' from within a script doesn't work

Why doesn't the 'export -f FUNCTION' work as expected in the following:

#!/bin/bash
target="$1"

[[ -z "$target" ]] && echo "No target specified." && exit 1

work() {
  bsdtar -xOf "$target" .PKGINFO | egrep -w 'pkgname|arch|pkgdesc|group|conflict|depend|replaces' | sed -e 's/pkgname/\npkgname/' >> /scratch/pkgs.log
}

export -f work
find /scratch/repo -name "$target*.pkg.tar.xz" | parallel work

It errors out when called:

% ~/bin/repo/check_pkgs broadcom
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work
zsh:1: command not found: do_work

CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2012-11-22 22:12:05

Thaodan
Member
From: Dortmund, Nordrein-Westfalen
Registered: 2012-04-28
Posts: 434

Re: Using 'export -f FUNCTION' from within a script doesn't work

My try running this from bash?


Linux odin 3.13.1-pf #1 SMP PREEMPT Wed Mar 5 21:47:28 CET 2014 x86_64 GNU/Linux

Offline

#3 2012-11-22 22:18:53

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,454
Website

Re: Using 'export -f FUNCTION' from within a script doesn't work

Yep... Same result.


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#4 2012-11-24 00:19:51

moetunes
Member
From: A comfortable couch
Registered: 2010-10-09
Posts: 1,019

Re: Using 'export -f FUNCTION' from within a script doesn't work

The command you are exporting is called work.
The command it fails on is do_work
so something's not right.


You're just jealous because the voices only talk to me.

Offline

#5 2012-11-24 01:52:22

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,092
Website

Re: Using 'export -f FUNCTION' from within a script doesn't work

It's also the wrong solution to be exporting functions...

Yay for ineffective crossposting... https://bbs.archlinux.org/viewtopic.php?id=153461

Offline

#6 2012-11-24 10:11:34

Awebb
Member
Registered: 2010-05-06
Posts: 4,178

Re: Using 'export -f FUNCTION' from within a script doesn't work

Why does zsh report a problem with a bash script?

Offline

#7 2012-11-24 14:34:37

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,454
Website

Re: Using 'export -f FUNCTION' from within a script doesn't work

moetunes wrote:

The command you are exporting is called work. The command it fails on is do_work

That was a copy/paste error based on me trying multiple scripts.  Sorry about the confusion.

% ./test linux
zsh:1: command not found: work
zsh:1: command not found: work
falconindy wrote:

It's also the wrong solution to be exporting functions...

Yay for ineffective crossposting... https://bbs.archlinux.org/viewtopic.php?id=153461

Exporting functions is recommended in the parallel man page.

The command must be an executable, a script, a composed command, or a function. If it is a function you need to export -f the function first. An alias will, however, not work (see why http://www.perlmonks.org/index.pl?node_id=484296).

Also, how is this a cross post?  The post you referenced is about parsing input, this one is about calling a function from within the parent script.

Awebb wrote:

Why does zsh report a problem with a bash script?

No idea smile

Last edited by graysky (2012-11-24 14:35:15)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#8 2012-11-24 16:50:42

graysky
Member
From: /run/user/1000
Registered: 2008-12-01
Posts: 8,454
Website

Re: Using 'export -f FUNCTION' from within a script doesn't work

Ah!  The problem is with zsh which is somehow ignoring the shebang in my script!  If I run it from a native bash prompt, it works as expected...why?

Last edited by graysky (2012-11-24 16:51:01)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

Board footer

Powered by FluxBB