Why does a file move/copy function only move one file at a time when using the “*” wildcard?Why does my shell script choke on whitespace or other special characters?Bash source — select the right function when two sourced files have the same function name?Move extension-less files with mvWhy alias inside function does not work?What does the double star/asterisk wildcard expand to?Why does a unquoted wildcard work remotely with scp?Which of the following shell operations are performed inside the function body when running a function definition and when calling a function?Why doesn't this loop process one file at a time?Wildcards in archive inclusion filesHandle filenames containing whitespaces passed to Bash function using wildcardHow to recursively move one file type but only when another file type is also present?
How can this shape perfectly cover a cube?
How to prevent cables getting intertwined
Huge Heap Table and table compression on SQL Server 2016
My husband's visa refused but mine wasn't -- can I travel?
Leaving job close to major deadlines
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
Is there a risk to write an invitation letter for a stranger to obtain a Czech (Schengen) visa?
Should I email my professor to clear up a (possibly very irrelevant) awkward misunderstanding?
Is my research statement supposed to lead to papers in top journals?
How to know whether to write accidentals as sharps or flats?
Background for black and white chart
How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?
How would Japanese people react to someone refusing to say “itadakimasu” for religious reasons?
Class to generate a pdf invoice
How do I become a better writer when I hate reading?
What kind of chart is this?
Catching a robber on one line
Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?
Does knowing the surface area of all faces uniquely determine a tetrahedron?
Does anyone recognize these rockets, and their location?
How to write a nice frame challenge?
Is the infant mortality rate among African-American babies in Youngstown, Ohio greater than that of babies in Iran?
Having some issue with notation in a Hilbert space
2 Managed Packages in 1 Dev Org
Why does a file move/copy function only move one file at a time when using the “*” wildcard?
Why does my shell script choke on whitespace or other special characters?Bash source — select the right function when two sourced files have the same function name?Move extension-less files with mvWhy alias inside function does not work?What does the double star/asterisk wildcard expand to?Why does a unquoted wildcard work remotely with scp?Which of the following shell operations are performed inside the function body when running a function definition and when calling a function?Why doesn't this loop process one file at a time?Wildcards in archive inclusion filesHandle filenames containing whitespaces passed to Bash function using wildcardHow to recursively move one file type but only when another file type is also present?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
function mv1 mv -n "$1" "targetdir" -v
mv1 *.png
It does only move the first .png file it finds, not all of them.
How can I make the command apply to all files that match the wildcards?
bash shell command-line wildcards function
add a comment |
function mv1 mv -n "$1" "targetdir" -v
mv1 *.png
It does only move the first .png file it finds, not all of them.
How can I make the command apply to all files that match the wildcards?
bash shell command-line wildcards function
add a comment |
function mv1 mv -n "$1" "targetdir" -v
mv1 *.png
It does only move the first .png file it finds, not all of them.
How can I make the command apply to all files that match the wildcards?
bash shell command-line wildcards function
function mv1 mv -n "$1" "targetdir" -v
mv1 *.png
It does only move the first .png file it finds, not all of them.
How can I make the command apply to all files that match the wildcards?
bash shell command-line wildcards function
bash shell command-line wildcards function
edited Jun 8 at 22:20
neverMind9
asked Jun 8 at 20:22
neverMind9neverMind9
693321
693321
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
mv1 *.png first expands the wildcard pattern *.png into the list of matching file names, then passes that list of file names to the function.
Then, inside the function $1 means: take the first argument to the function, split it where it contains whitespace, and replace any of the whitespace-separated parts that contain wildcard characters and match at least one file name by the list of matching file names. Sounds complicated? It is, and this behavior is only occasionally useful and is often problematic. This splitting and matching behavior only occurs if $1 occurs outside of double quotes, so the fix is easy: use double quotes. Always put double quotes around variable substitutions unless you have a good reason not to.
For example, if the current directory contains the two files A* algorithm.png and graph1.png, then mv1 *.png passes A* algorithm.png as the first argument to the function and graph1.png as the second argument. Then $1 is split into A* and algorithm.png. The pattern A* matches A* algorithm.png, and algorithm.png doesn't contain wildcard characters. So the function ends up running mv with the arguments -n, A* algorithm.png, algorithm.png, targetdir and -v. If you correct the function to
function mv1 mv -n "$1" "targetdir" -v
then it will correctly move the first file.
To process all the arguments, tell the shell to process all arguments and not just the first. You can use "$@" to mean the full list of arguments passed to the function.
function mv1 mv -n "$@" "targetdir" -v
This is almost correct, but it still fails if a file name happens to begin with the character -, because mv will treat that argument as an option. Pass -- to mv to tell it “no more options after this point”. This is a very common convention that most commands support.
function mv1 wc -l ;
A remaining problem is that if mv fails, this function returns a success status, because the exit status of commands on the left-hand side of a pipe is ignored. In bash (or ksh), you can use set -o pipefail to make the pipeline fail. Note that setting this option may cause other code running in the same shell to fail, so you should set it locally in the function, which is possible since bash 4.4.
function mv1
local -
set -o pipefail
mv -n -v -- "$@" "targetdir"
In earlier versions, setting pipefail would be fragile, so it would be better to check PIPESTATUS explicitly instead.
function mv1 wc -l
((!$PIPESTATUS[0] && !$PIPESTATUS[1]))
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
You could also usereturn "$PIPESTATUS[0]"(immediately after themv | wcpipeline) instead of messing withpipefail.
– Gordon Davisson
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?$1, without quotes, splits at whitespace.
– Gilles
Jun 9 at 8:20
|
show 1 more comment
$1 is the first argument to the function, here the first file that matches *.png. I guess that "$@" is what you want to use instead of $1.
1
$@or$*is very rarely useful. To take all the arguments, use"$@". The double quotes are very important.
– Gilles
Jun 8 at 21:10
Thanks alot for showing me$@! Very useful!
– neverMind9
Jun 8 at 22:19
add a comment |
You would have to use mv1 *.png.
When interacting with functions, the Linux Terminal does not pass the asterisk directly to the command, but selects the first matching parameter and passes that one to the command.
To allow the asterisk to pass through directly, one needs to escape the asterisk using a backslash.
2
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
1
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if$1is*.png).
– pts
Jun 9 at 10:09
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f523763%2fwhy-does-a-file-move-copy-function-only-move-one-file-at-a-time-when-using-the%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
mv1 *.png first expands the wildcard pattern *.png into the list of matching file names, then passes that list of file names to the function.
Then, inside the function $1 means: take the first argument to the function, split it where it contains whitespace, and replace any of the whitespace-separated parts that contain wildcard characters and match at least one file name by the list of matching file names. Sounds complicated? It is, and this behavior is only occasionally useful and is often problematic. This splitting and matching behavior only occurs if $1 occurs outside of double quotes, so the fix is easy: use double quotes. Always put double quotes around variable substitutions unless you have a good reason not to.
For example, if the current directory contains the two files A* algorithm.png and graph1.png, then mv1 *.png passes A* algorithm.png as the first argument to the function and graph1.png as the second argument. Then $1 is split into A* and algorithm.png. The pattern A* matches A* algorithm.png, and algorithm.png doesn't contain wildcard characters. So the function ends up running mv with the arguments -n, A* algorithm.png, algorithm.png, targetdir and -v. If you correct the function to
function mv1 mv -n "$1" "targetdir" -v
then it will correctly move the first file.
To process all the arguments, tell the shell to process all arguments and not just the first. You can use "$@" to mean the full list of arguments passed to the function.
function mv1 mv -n "$@" "targetdir" -v
This is almost correct, but it still fails if a file name happens to begin with the character -, because mv will treat that argument as an option. Pass -- to mv to tell it “no more options after this point”. This is a very common convention that most commands support.
function mv1 wc -l ;
A remaining problem is that if mv fails, this function returns a success status, because the exit status of commands on the left-hand side of a pipe is ignored. In bash (or ksh), you can use set -o pipefail to make the pipeline fail. Note that setting this option may cause other code running in the same shell to fail, so you should set it locally in the function, which is possible since bash 4.4.
function mv1
local -
set -o pipefail
mv -n -v -- "$@" "targetdir"
In earlier versions, setting pipefail would be fragile, so it would be better to check PIPESTATUS explicitly instead.
function mv1 wc -l
((!$PIPESTATUS[0] && !$PIPESTATUS[1]))
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
You could also usereturn "$PIPESTATUS[0]"(immediately after themv | wcpipeline) instead of messing withpipefail.
– Gordon Davisson
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?$1, without quotes, splits at whitespace.
– Gilles
Jun 9 at 8:20
|
show 1 more comment
mv1 *.png first expands the wildcard pattern *.png into the list of matching file names, then passes that list of file names to the function.
Then, inside the function $1 means: take the first argument to the function, split it where it contains whitespace, and replace any of the whitespace-separated parts that contain wildcard characters and match at least one file name by the list of matching file names. Sounds complicated? It is, and this behavior is only occasionally useful and is often problematic. This splitting and matching behavior only occurs if $1 occurs outside of double quotes, so the fix is easy: use double quotes. Always put double quotes around variable substitutions unless you have a good reason not to.
For example, if the current directory contains the two files A* algorithm.png and graph1.png, then mv1 *.png passes A* algorithm.png as the first argument to the function and graph1.png as the second argument. Then $1 is split into A* and algorithm.png. The pattern A* matches A* algorithm.png, and algorithm.png doesn't contain wildcard characters. So the function ends up running mv with the arguments -n, A* algorithm.png, algorithm.png, targetdir and -v. If you correct the function to
function mv1 mv -n "$1" "targetdir" -v
then it will correctly move the first file.
To process all the arguments, tell the shell to process all arguments and not just the first. You can use "$@" to mean the full list of arguments passed to the function.
function mv1 mv -n "$@" "targetdir" -v
This is almost correct, but it still fails if a file name happens to begin with the character -, because mv will treat that argument as an option. Pass -- to mv to tell it “no more options after this point”. This is a very common convention that most commands support.
function mv1 wc -l ;
A remaining problem is that if mv fails, this function returns a success status, because the exit status of commands on the left-hand side of a pipe is ignored. In bash (or ksh), you can use set -o pipefail to make the pipeline fail. Note that setting this option may cause other code running in the same shell to fail, so you should set it locally in the function, which is possible since bash 4.4.
function mv1
local -
set -o pipefail
mv -n -v -- "$@" "targetdir"
In earlier versions, setting pipefail would be fragile, so it would be better to check PIPESTATUS explicitly instead.
function mv1 wc -l
((!$PIPESTATUS[0] && !$PIPESTATUS[1]))
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
You could also usereturn "$PIPESTATUS[0]"(immediately after themv | wcpipeline) instead of messing withpipefail.
– Gordon Davisson
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?$1, without quotes, splits at whitespace.
– Gilles
Jun 9 at 8:20
|
show 1 more comment
mv1 *.png first expands the wildcard pattern *.png into the list of matching file names, then passes that list of file names to the function.
Then, inside the function $1 means: take the first argument to the function, split it where it contains whitespace, and replace any of the whitespace-separated parts that contain wildcard characters and match at least one file name by the list of matching file names. Sounds complicated? It is, and this behavior is only occasionally useful and is often problematic. This splitting and matching behavior only occurs if $1 occurs outside of double quotes, so the fix is easy: use double quotes. Always put double quotes around variable substitutions unless you have a good reason not to.
For example, if the current directory contains the two files A* algorithm.png and graph1.png, then mv1 *.png passes A* algorithm.png as the first argument to the function and graph1.png as the second argument. Then $1 is split into A* and algorithm.png. The pattern A* matches A* algorithm.png, and algorithm.png doesn't contain wildcard characters. So the function ends up running mv with the arguments -n, A* algorithm.png, algorithm.png, targetdir and -v. If you correct the function to
function mv1 mv -n "$1" "targetdir" -v
then it will correctly move the first file.
To process all the arguments, tell the shell to process all arguments and not just the first. You can use "$@" to mean the full list of arguments passed to the function.
function mv1 mv -n "$@" "targetdir" -v
This is almost correct, but it still fails if a file name happens to begin with the character -, because mv will treat that argument as an option. Pass -- to mv to tell it “no more options after this point”. This is a very common convention that most commands support.
function mv1 wc -l ;
A remaining problem is that if mv fails, this function returns a success status, because the exit status of commands on the left-hand side of a pipe is ignored. In bash (or ksh), you can use set -o pipefail to make the pipeline fail. Note that setting this option may cause other code running in the same shell to fail, so you should set it locally in the function, which is possible since bash 4.4.
function mv1
local -
set -o pipefail
mv -n -v -- "$@" "targetdir"
In earlier versions, setting pipefail would be fragile, so it would be better to check PIPESTATUS explicitly instead.
function mv1 wc -l
((!$PIPESTATUS[0] && !$PIPESTATUS[1]))
mv1 *.png first expands the wildcard pattern *.png into the list of matching file names, then passes that list of file names to the function.
Then, inside the function $1 means: take the first argument to the function, split it where it contains whitespace, and replace any of the whitespace-separated parts that contain wildcard characters and match at least one file name by the list of matching file names. Sounds complicated? It is, and this behavior is only occasionally useful and is often problematic. This splitting and matching behavior only occurs if $1 occurs outside of double quotes, so the fix is easy: use double quotes. Always put double quotes around variable substitutions unless you have a good reason not to.
For example, if the current directory contains the two files A* algorithm.png and graph1.png, then mv1 *.png passes A* algorithm.png as the first argument to the function and graph1.png as the second argument. Then $1 is split into A* and algorithm.png. The pattern A* matches A* algorithm.png, and algorithm.png doesn't contain wildcard characters. So the function ends up running mv with the arguments -n, A* algorithm.png, algorithm.png, targetdir and -v. If you correct the function to
function mv1 mv -n "$1" "targetdir" -v
then it will correctly move the first file.
To process all the arguments, tell the shell to process all arguments and not just the first. You can use "$@" to mean the full list of arguments passed to the function.
function mv1 mv -n "$@" "targetdir" -v
This is almost correct, but it still fails if a file name happens to begin with the character -, because mv will treat that argument as an option. Pass -- to mv to tell it “no more options after this point”. This is a very common convention that most commands support.
function mv1 wc -l ;
A remaining problem is that if mv fails, this function returns a success status, because the exit status of commands on the left-hand side of a pipe is ignored. In bash (or ksh), you can use set -o pipefail to make the pipeline fail. Note that setting this option may cause other code running in the same shell to fail, so you should set it locally in the function, which is possible since bash 4.4.
function mv1
local -
set -o pipefail
mv -n -v -- "$@" "targetdir"
In earlier versions, setting pipefail would be fragile, so it would be better to check PIPESTATUS explicitly instead.
function mv1 wc -l
((!$PIPESTATUS[0] && !$PIPESTATUS[1]))
edited Jun 9 at 22:50
answered Jun 8 at 21:08
GillesGilles
558k13411451656
558k13411451656
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
You could also usereturn "$PIPESTATUS[0]"(immediately after themv | wcpipeline) instead of messing withpipefail.
– Gordon Davisson
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?$1, without quotes, splits at whitespace.
– Gilles
Jun 9 at 8:20
|
show 1 more comment
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
You could also usereturn "$PIPESTATUS[0]"(immediately after themv | wcpipeline) instead of messing withpipefail.
– Gordon Davisson
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?$1, without quotes, splits at whitespace.
– Gilles
Jun 9 at 8:20
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
I already made that first correction before I posted the question, but I forgot to correct it in the question as well.
– neverMind9
Jun 8 at 22:23
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
“Pass -- to mv to tell it “no more options after this point”.” – Thanks alot. Didn't knew that until now.
– neverMind9
Jun 8 at 22:24
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
cite for "$1" splitting at whitespace
– Jasen
Jun 9 at 7:04
You could also use
return "$PIPESTATUS[0]" (immediately after the mv | wc pipeline) instead of messing with pipefail.– Gordon Davisson
Jun 9 at 8:20
You could also use
return "$PIPESTATUS[0]" (immediately after the mv | wc pipeline) instead of messing with pipefail.– Gordon Davisson
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?
$1, without quotes, splits at whitespace.– Gilles
Jun 9 at 8:20
@Jasen It doesn't. Where did you read that?
$1, without quotes, splits at whitespace.– Gilles
Jun 9 at 8:20
|
show 1 more comment
$1 is the first argument to the function, here the first file that matches *.png. I guess that "$@" is what you want to use instead of $1.
1
$@or$*is very rarely useful. To take all the arguments, use"$@". The double quotes are very important.
– Gilles
Jun 8 at 21:10
Thanks alot for showing me$@! Very useful!
– neverMind9
Jun 8 at 22:19
add a comment |
$1 is the first argument to the function, here the first file that matches *.png. I guess that "$@" is what you want to use instead of $1.
1
$@or$*is very rarely useful. To take all the arguments, use"$@". The double quotes are very important.
– Gilles
Jun 8 at 21:10
Thanks alot for showing me$@! Very useful!
– neverMind9
Jun 8 at 22:19
add a comment |
$1 is the first argument to the function, here the first file that matches *.png. I guess that "$@" is what you want to use instead of $1.
$1 is the first argument to the function, here the first file that matches *.png. I guess that "$@" is what you want to use instead of $1.
edited Jun 8 at 21:07
Stephen Kitt
190k26448524
190k26448524
answered Jun 8 at 20:55
JarivaaJarivaa
515
515
1
$@or$*is very rarely useful. To take all the arguments, use"$@". The double quotes are very important.
– Gilles
Jun 8 at 21:10
Thanks alot for showing me$@! Very useful!
– neverMind9
Jun 8 at 22:19
add a comment |
1
$@or$*is very rarely useful. To take all the arguments, use"$@". The double quotes are very important.
– Gilles
Jun 8 at 21:10
Thanks alot for showing me$@! Very useful!
– neverMind9
Jun 8 at 22:19
1
1
$@ or $* is very rarely useful. To take all the arguments, use "$@". The double quotes are very important.– Gilles
Jun 8 at 21:10
$@ or $* is very rarely useful. To take all the arguments, use "$@". The double quotes are very important.– Gilles
Jun 8 at 21:10
Thanks alot for showing me
$@! Very useful!– neverMind9
Jun 8 at 22:19
Thanks alot for showing me
$@! Very useful!– neverMind9
Jun 8 at 22:19
add a comment |
You would have to use mv1 *.png.
When interacting with functions, the Linux Terminal does not pass the asterisk directly to the command, but selects the first matching parameter and passes that one to the command.
To allow the asterisk to pass through directly, one needs to escape the asterisk using a backslash.
2
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
1
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if$1is*.png).
– pts
Jun 9 at 10:09
add a comment |
You would have to use mv1 *.png.
When interacting with functions, the Linux Terminal does not pass the asterisk directly to the command, but selects the first matching parameter and passes that one to the command.
To allow the asterisk to pass through directly, one needs to escape the asterisk using a backslash.
2
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
1
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if$1is*.png).
– pts
Jun 9 at 10:09
add a comment |
You would have to use mv1 *.png.
When interacting with functions, the Linux Terminal does not pass the asterisk directly to the command, but selects the first matching parameter and passes that one to the command.
To allow the asterisk to pass through directly, one needs to escape the asterisk using a backslash.
You would have to use mv1 *.png.
When interacting with functions, the Linux Terminal does not pass the asterisk directly to the command, but selects the first matching parameter and passes that one to the command.
To allow the asterisk to pass through directly, one needs to escape the asterisk using a backslash.
answered Jun 8 at 20:22
neverMind9neverMind9
693321
693321
2
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
1
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if$1is*.png).
– pts
Jun 9 at 10:09
add a comment |
2
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
1
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if$1is*.png).
– pts
Jun 9 at 10:09
2
2
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
You understood part of the problem right, but your solution is not good. In particular, it doesn't work with file names containing whitespace. See my answer for a correct solution and explanations.
– Gilles
Jun 8 at 21:09
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles Thank you for the answer.
– neverMind9
Jun 8 at 21:34
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
@Gilles …but does that really justify the downvote that was hammered onto my answer?
– neverMind9
Jun 8 at 21:35
1
1
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if
$1 is *.png).– pts
Jun 9 at 10:09
This answer doesn't answer this part of the question: How can I make the command apply to all files that match the wildcards? I can't see an easy way to expand this answer, because Bash doesn't have a safe way to apply globbing only to the value of a veriable (e.g. if
$1 is *.png).– pts
Jun 9 at 10:09
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f523763%2fwhy-does-a-file-move-copy-function-only-move-one-file-at-a-time-when-using-the%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown