in reply to Calling Shell funtion in Perl script

To do it you need to exec your profile in shell data:
perl -e 'system(". .bash_rc; test_shell")' __END__ TEST on shell function!!!
initial dot equivales a source command

.bash_rc

test_shell() { echo "TEST on shell function!!!" }

--
Marco Antonio
Rio-PM

Replies are listed 'Best First'.
Re^2: Calling Shell funtion in Perl script
by Anonymous Monk on May 24, 2005 at 15:36 UTC
    This pscnt function is to determine if any program name (and parameter) passed in is actually a running process. If so, returns count of running instances. I tried this code, but I get count as 2. my $running = `. ~/.profil > /dev/null; pscnt $app_name $parameter`; I am not sure if the code is correct. So, please help me to sort out this issue.

      This should work.

      In . ~/.profil > /dev/null, is the missing e a typo that appears in your real code too?

      Also the `` operator is calling /bin/sh, so if you are using a different shell (such as zsh), this may not work. Even if you are using bash, it may be invoked as sh and thus it is running in POSIX compatibility mode. You could try `set +o posix; . ~/.profile > /dev/null; whatever`

      If the code still doesn't work, try this for debugging so that you see what commands the shell runs: my $result = `set -v; set +o posix; . ~/.profile > /dev/null; whatever`

      Also, you might want to move the shell function from your profile to a separate shell script, so that you don't have to run the whole profile from our perl script. (You can still source the separate file from your profile.)