How does wildcard expansion work with two arguments?

How does wildcard expansion work with two arguments?

Wildcard expansion is based on the file name (or directory name), not the file type. With two arguments, the target can be either a file or directory. In the case of a file, the target file is removed and replaced by a copy of the source file. If the target is a directory, a copy of the source file is placed in that directory.

Can a wildcard be interpreted as a switch?

The wildcard ‘*’ expands to the filename which gets interpreted as a switch. You can also cause chaos by putting spaces, tabs and newlines in file names. If the last part parameter is a directory, cp will copy the specified files to it.

When to declare destination after using wildcard in shell?

Always declare at the very end a destination after using a wildcard. It’s not a bug, it’s a side-effect doing of wildcard expansion once in the shell rather than implementing it in every program. Now, there are some much stranger ways you can trip yourself up with this, especially by creating files whose names start with “-“.

Which is a side effect of Bash wildcards?

This is a side effect of bash wildcards and cannot be called a bug. You seem to understand what is happening perfectly well. In your example, *pdf indeed expands to file1.pdf file2.pdf this_is_a_folder.pdf.

How to support wildcard characters in cmdlet parameters?

When you design cmdlets that support wildcard characters, allow for combinations of wildcard characters. For example, the following command uses the Get-ChildItem cmdlet to retrieve all the .txt files that are in the c:\\Techdocs folder and that begin with the letters “a” through “l.”

When to use range wildcard in a file name?

The previous command uses the range wildcard [a-l] to specify that the file name should begin with the characters “a” through “l” and uses the * wildcard character as a placeholder for any characters between the first letter of the filename and the .txt extension.