xcm said:
and I know "cd" is a internal command of shell.
So then,
system 'cd';
is totally useless.
What is it that you are really trying to accomplish?
Do you know that you can change the current working directly in
a manner that may actually be useful for something?
perldoc -f chdir
I only want to know if system() always pass the command to shell or derectly
use exec family to execute the command.
The docs for system() answer your question:
Note that argument processing varies depending on the
number of arguments. If there is more than one argument in LIST,
or if LIST is an array with more than one value, starts the program
given by the first element of the list with arguments given by the
rest of the list. If there is only one scalar argument, the argument
is checked for shell metacharacters, and if there are any, the
entire argument is passed to the system's command shell for parsing
(this is C</bin/sh -c> on Unix platforms, but varies on other
platforms). If there are no shell metacharacters in the argument,
it is split into words and passed directly to C<execvp>, which is
more efficient.
Q: How many args are you passing to system()?
A: One.
Q: Does that single argument contain any shell metacharacters?
A: No.
Q: Will system() invoke a shell then?
A: No.
So attempting to run a shell builtin will fail, because there is no shell.
You could call it with one arg that _does_ contain shell metacharacters:
system 'cd ~'
Or, probably better, call system with a list, and explicitly
call the shell that you want:
system '/bin/bash', '-c', 'cd'