How is the wildcard * interpreted as a command?2019 Community Moderator ElectionWorking of the [0-9]Execute command within variableInternal expansion with the find command and wildcard characterCan a bash script tell what directory the user is when they run the script?Selecting non-existent files with wildcard/regexFind wildcard search not working in /etcPurpose of '&& bash' in a command (not the '&&' part, the 'bash' part)Why does a 'sudo -i' login shell break a here-doc command string argument?Bash script copy file to user's (wildcard) home dirBash wget with variables and wildcard

weren't playing vs didn't play

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?

What problems would a superhuman have whose skin is constantly hot?

They call me Inspector Morse

Can Mathematica be used to create an Artistic 3D extrusion from a 2D image and wrap a line pattern around it?

Do items de-spawn in Diablo?

How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?

PTIJ: wiping amalek’s memory?

What are some noteworthy "mic-drop" moments in math?

How is the wildcard * interpreted as a command?

Is it possible to avoid unpacking when merging Association?

If I receive a SOS signal, what is the proper response?

Vocabulary for giving just numbers, not a full answer

Counting all the hearts

Sort with one element at the end

finite abelian groups tensor product.

Linux Ubuntu 18.04 Full Backup

Can I pump my MTB tire to max (55 psi / 380 kPa) without the tube inside bursting?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

Is "conspicuously missing" or "conspicuously" the subject of this sentence?

When traveling to Europe from North America, do I need to purchase a different power strip?

Reverse string, can I make it faster?

Was Luke Skywalker the leader of the Rebel forces on Hoth?

Are babies of evil humanoid species inherently evil?



How is the wildcard * interpreted as a command?



2019 Community Moderator ElectionWorking of the [0-9]Execute command within variableInternal expansion with the find command and wildcard characterCan a bash script tell what directory the user is when they run the script?Selecting non-existent files with wildcard/regexFind wildcard search not working in /etcPurpose of '&& bash' in a command (not the '&&' part, the 'bash' part)Why does a 'sudo -i' login shell break a here-doc command string argument?Bash script copy file to user's (wildcard) home dirBash wget with variables and wildcard










1















I know how * is interpreted in commands like ls for example. But when trying to run * as a command the shell tries to execute the first file or directory in your working directory. Why is this? How does the shell understand *?










share|improve this question









New contributor




osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    1















    I know how * is interpreted in commands like ls for example. But when trying to run * as a command the shell tries to execute the first file or directory in your working directory. Why is this? How does the shell understand *?










    share|improve this question









    New contributor




    osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      1












      1








      1








      I know how * is interpreted in commands like ls for example. But when trying to run * as a command the shell tries to execute the first file or directory in your working directory. Why is this? How does the shell understand *?










      share|improve this question









      New contributor




      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I know how * is interpreted in commands like ls for example. But when trying to run * as a command the shell tries to execute the first file or directory in your working directory. Why is this? How does the shell understand *?







      bash wildcards






      share|improve this question









      New contributor




      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 1 hour ago









      Glorfindel

      2971411




      2971411






      New contributor




      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 hours ago









      osmakosmak

      83




      83




      New contributor




      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      osmak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes


















          5














          That's quite simple, actually. Unlike in some other operating systems, in Unixes, it's the shell that expands filename wildcards. It expands parameter expansions and globs first, then uses the (now) first word as the name for the command to run.



          This is also why files named with a leading dash can be troublesome: a glob like * will expand to the file names, and a name starting with a dash may be taken as an option. (The scary example being that a file called -r in the working directory would make rm * remove everything recursively...)



          Usually, one wouldn't use * as the first item on any command line, though, so having the first file determine the command to run in that case isn't likely to cause problems.






          share|improve this answer

























          • I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

            – Michael Homer
            2 hours ago











          • OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

            – osmak
            2 hours ago











          • @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

            – ilkkachu
            2 hours ago











          • @osmak That is a correct understanding.

            – Kusalananda
            2 hours ago






          • 1





            A file named -r is bad, but one named -rf is even worse.

            – Monty Harder
            20 mins ago










          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
          );



          );






          osmak is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505707%2fhow-is-the-wildcard-interpreted-as-a-command%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          That's quite simple, actually. Unlike in some other operating systems, in Unixes, it's the shell that expands filename wildcards. It expands parameter expansions and globs first, then uses the (now) first word as the name for the command to run.



          This is also why files named with a leading dash can be troublesome: a glob like * will expand to the file names, and a name starting with a dash may be taken as an option. (The scary example being that a file called -r in the working directory would make rm * remove everything recursively...)



          Usually, one wouldn't use * as the first item on any command line, though, so having the first file determine the command to run in that case isn't likely to cause problems.






          share|improve this answer

























          • I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

            – Michael Homer
            2 hours ago











          • OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

            – osmak
            2 hours ago











          • @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

            – ilkkachu
            2 hours ago











          • @osmak That is a correct understanding.

            – Kusalananda
            2 hours ago






          • 1





            A file named -r is bad, but one named -rf is even worse.

            – Monty Harder
            20 mins ago















          5














          That's quite simple, actually. Unlike in some other operating systems, in Unixes, it's the shell that expands filename wildcards. It expands parameter expansions and globs first, then uses the (now) first word as the name for the command to run.



          This is also why files named with a leading dash can be troublesome: a glob like * will expand to the file names, and a name starting with a dash may be taken as an option. (The scary example being that a file called -r in the working directory would make rm * remove everything recursively...)



          Usually, one wouldn't use * as the first item on any command line, though, so having the first file determine the command to run in that case isn't likely to cause problems.






          share|improve this answer

























          • I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

            – Michael Homer
            2 hours ago











          • OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

            – osmak
            2 hours ago











          • @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

            – ilkkachu
            2 hours ago











          • @osmak That is a correct understanding.

            – Kusalananda
            2 hours ago






          • 1





            A file named -r is bad, but one named -rf is even worse.

            – Monty Harder
            20 mins ago













          5












          5








          5







          That's quite simple, actually. Unlike in some other operating systems, in Unixes, it's the shell that expands filename wildcards. It expands parameter expansions and globs first, then uses the (now) first word as the name for the command to run.



          This is also why files named with a leading dash can be troublesome: a glob like * will expand to the file names, and a name starting with a dash may be taken as an option. (The scary example being that a file called -r in the working directory would make rm * remove everything recursively...)



          Usually, one wouldn't use * as the first item on any command line, though, so having the first file determine the command to run in that case isn't likely to cause problems.






          share|improve this answer















          That's quite simple, actually. Unlike in some other operating systems, in Unixes, it's the shell that expands filename wildcards. It expands parameter expansions and globs first, then uses the (now) first word as the name for the command to run.



          This is also why files named with a leading dash can be troublesome: a glob like * will expand to the file names, and a name starting with a dash may be taken as an option. (The scary example being that a file called -r in the working directory would make rm * remove everything recursively...)



          Usually, one wouldn't use * as the first item on any command line, though, so having the first file determine the command to run in that case isn't likely to cause problems.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 1 hour ago

























          answered 3 hours ago









          ilkkachuilkkachu

          60.9k1098174




          60.9k1098174












          • I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

            – Michael Homer
            2 hours ago











          • OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

            – osmak
            2 hours ago











          • @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

            – ilkkachu
            2 hours ago











          • @osmak That is a correct understanding.

            – Kusalananda
            2 hours ago






          • 1





            A file named -r is bad, but one named -rf is even worse.

            – Monty Harder
            20 mins ago

















          • I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

            – Michael Homer
            2 hours ago











          • OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

            – osmak
            2 hours ago











          • @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

            – ilkkachu
            2 hours ago











          • @osmak That is a correct understanding.

            – Kusalananda
            2 hours ago






          • 1





            A file named -r is bad, but one named -rf is even worse.

            – Monty Harder
            20 mins ago
















          I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

          – Michael Homer
          2 hours ago





          I think this example misses an important point out, that filename expansion is not subject to further field splitting, unlike parameter expansion, so filenames with spaces are still safe.

          – Michael Homer
          2 hours ago













          OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

          – osmak
          2 hours ago





          OK, so I think I misunderstood how the * work in the first place. I thought that it is a common syntax used in Linux commands. But, if I understood your answer correctly, then filename expansion is a shell feature not a command feature. So what happened is that * got replaced by all file or directory names in PWD but when the shell tried executing the first one it produced the error I saw.

          – osmak
          2 hours ago













          @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

          – ilkkachu
          2 hours ago





          @osmak, yeah, it's a shell feature on Unixes. Easier that way, so each and every program doesn't have to implement it. Though of course programs like find know how to expand similar patterns, too (e.g. file -name "*.txt")

          – ilkkachu
          2 hours ago













          @osmak That is a correct understanding.

          – Kusalananda
          2 hours ago





          @osmak That is a correct understanding.

          – Kusalananda
          2 hours ago




          1




          1





          A file named -r is bad, but one named -rf is even worse.

          – Monty Harder
          20 mins ago





          A file named -r is bad, but one named -rf is even worse.

          – Monty Harder
          20 mins ago










          osmak is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          osmak is a new contributor. Be nice, and check out our Code of Conduct.












          osmak is a new contributor. Be nice, and check out our Code of Conduct.











          osmak is a new contributor. Be nice, and check out our Code of Conduct.














          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f505707%2fhow-is-the-wildcard-interpreted-as-a-command%23new-answer', 'question_page');

          );

          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







          -bash, wildcards

          Popular posts from this blog

          Creating 100m^2 grid automatically using QGIS?Creating grid constrained within polygon in QGIS?Createing polygon layer from point data using QGIS?Creating vector grid using QGIS?Creating grid polygons from coordinates using R or PythonCreating grid from spatio temporal point data?Creating fields in attributes table using other layers using QGISCreate .shp vector grid in QGISQGIS Creating 4km point grid within polygonsCreate a vector grid over a raster layerVector Grid Creates just one grid

          Why is this plane circling around the Lucknow airport every day?Why do aircraft on Flight Radar 24 jump around randomly sometimes?What airport has this walkway over a taxiway?How does Chicago O'Hare's tower sequence aircraft at peak capacity?Which airport is featured in this Delta commercial?After a crash, for how long is the airport closed?Can a passenger plane stand still in the air, or hover at a fixed location above a ground?What are those trucks towing around, and why?What is this airport outside of Cairo, Egypt?Which US airport has the lowest circling MDH?What is this airport video?

          What is this called? Old film camera viewer?What makes a good film camera?What to do with an old film camera?What should one look for when buying a used film camera?What is the value and age of this pre-1967 Ricoh 35 mm camera?DSLR recommendation, question about old Canon 35mm film Camera & lensesCan anyone identify the silver rangefinder-style camera in this advertisement?What kind of a Polaroid 600-camera is this?Will an old film camera still work even when not used in a very long time?What is this camera / Can I develop the film?How to fit an action camera into antique (bellows) housing?What to check when buying used and old film bodies?