in reply to system & exec

My script can not work system using source.

That's because "source" isn't a valid command in your perl's default shell. Use "." instead and it should work fine, as demonstrated below. Although, since you are shelling out there is not really any practical difference between sourcing the script with "." and just executing it (but that's a different question and is likely the X in your XY Problem)

$ cat script.sh echo Woo-hoo! $ cat yang.pl #!/usr/bin/env perl use strict; use warnings; system '. ./script.sh'; $ ./yang.pl Woo-hoo! $

Replies are listed 'Best First'.
Re^2: system & exec
by ikegami (Patriarch) on Jul 28, 2018 at 19:17 UTC

    I find it hard to believe their /bin/sh understands . but not source.

      I find it hard to believe their /bin/sh understands . but not source.

      source is a bashism. Having a /bin/sh that behaves like a bash is pure luck. Linux had bash as default shell for a long time, but even on Linux, you can't rely on that any more. The *BSDs and commercial Unixes have changed their default shells several times. See https://www.in-ulm.de/~mascheck/various/shells/ for details.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      $ cat yangsource.pl #!/usr/bin/env perl use strict; use warnings; system 'source ./script.sh'; $ ./yangsource.pl Can't exec "source": No such file or directory at ./yangsource.pl line + 5. $

      I find your lack of faith disturbing