I am seeing "xargs" behaviour that seems to be quite unexpected, in my experience. I use "ls" to find a matching folder name and sending it to "cd" using "xargs". I get the message that the folder doesn't exist. If I don't use "xargs", however, the "cd" works. Also, if I do use "xargs" but send it to "ls" instead of "cd", it also works.
# Identify desired directory
ls -d *[Aa]nt*
201909+ants/
# Print the desired command with "echo"
ls -d *[Aa]nt* | xargs echo cd
cd 201909+ants/
# Execute the desired command and get error
ls -d *[Aa]nt* | xargs cd
xargs: cd: No such file or directory
# Confirm that the desired command without "xargs"
cd 201909+ants # This works no problem
cd .. # Go back up
cd 201909+ants/ # This works no problem
cd .. # Go back up
# Confirm that "xargs" with "ls"
ls -d *[Aa]nt* | xargs ls -d
201909+ants/
I'm convinced that this is an ID1OT problem between the keyboard and chair. Can anyone point out where my error lies?
I am using Cygwin's Bash, but rarely do I see a disparity with Linux. I can't remember the last time I saw such a disparity.