Why does $<filename not run the cmd from `filename` but $`<filename` and $exec<filename works?Why does initramfs mount the root filesystem read-onlyWhy is the exec option not listed in /proc/mounts?When does Linux send a root mail and how to force it for testing purposes?BashScript works from Terminal but not from CronTabThe program called by the init.d works by itself, but not when the init.d itself runsWhy does bash parameter expansion not work inside systemd service files?Sending special characters and new lines via KANNELNFSv3 works but not NFSv4 on ArmbianEcho to SerialportX11 can run on ereader via ssh -X, but unable to use the touch-screen as the main display

Multi tool use
Multi tool use

What do the Banks children have against barley water?

Is there a familial term for apples and pears?

What is the offset in a seaplane's hull?

How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?

COUNT(*) or MAX(id) - which is faster?

Is there a name of the flying bionic bird?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

Where else does the Shulchan Aruch quote an authority by name?

How to answer pointed "are you quitting" questioning when I don't want them to suspect

How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)

aging parents with no investments

Ideas for 3rd eye abilities

Domain expired, GoDaddy holds it and is asking more money

Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Typesetting a double Over Dot on top of a symbol

Why doesn't a const reference extend the life of a temporary object passed via a function?

How can I fix this gap between bookcases I made?

Add an angle to a sphere

Was there ever an axiom rendered a theorem?

Unbreakable Formation vs. Cry of the Carnarium

What is it called when one voice type sings a 'solo'?

How can I add custom success page

Why is my log file so massive? 22gb. I am running log backups



Why does $

Why does initramfs mount the root filesystem read-onlyWhy is the exec option not listed in /proc/mounts?When does Linux send a root mail and how to force it for testing purposes?BashScript works from Terminal but not from CronTabThe program called by the init.d works by itself, but not when the init.d itself runsWhy does bash parameter expansion not work inside systemd service files?Sending special characters and new lines via KANNELNFSv3 works but not NFSv4 on ArmbianEcho to SerialportX11 can run on ereader via ssh -X, but unable to use the touch-screen as the main display






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















root@raspberrypi:~# cat >test
echo succeed
root@raspberrypi:~# <test
root@raspberrypi:~# `<test`
succeed


i guess the reason is a missing of enter signal.But how to send enter










share|improve this question









New contributor




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




















  • If <test ran the shell commands in test, then how would one be able to redirect the contents of a file into a command, as in cat <test?

    – Kusalananda
    Apr 5 at 9:14











  • Do you mean that “<filename” like input something "eof".not "enter"?

    – Jack Walter
    Apr 6 at 2:42

















0















root@raspberrypi:~# cat >test
echo succeed
root@raspberrypi:~# <test
root@raspberrypi:~# `<test`
succeed


i guess the reason is a missing of enter signal.But how to send enter










share|improve this question









New contributor




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




















  • If <test ran the shell commands in test, then how would one be able to redirect the contents of a file into a command, as in cat <test?

    – Kusalananda
    Apr 5 at 9:14











  • Do you mean that “<filename” like input something "eof".not "enter"?

    – Jack Walter
    Apr 6 at 2:42













0












0








0








root@raspberrypi:~# cat >test
echo succeed
root@raspberrypi:~# <test
root@raspberrypi:~# `<test`
succeed


i guess the reason is a missing of enter signal.But how to send enter










share|improve this question









New contributor




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












root@raspberrypi:~# cat >test
echo succeed
root@raspberrypi:~# <test
root@raspberrypi:~# `<test`
succeed


i guess the reason is a missing of enter signal.But how to send enter







linux bash






share|improve this question









New contributor




Jack Walter 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




Jack Walter 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 Apr 5 at 18:32









Paradox

478317




478317






New contributor




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









asked Apr 5 at 8:26









Jack WalterJack Walter

257




257




New contributor




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





New contributor





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






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












  • If <test ran the shell commands in test, then how would one be able to redirect the contents of a file into a command, as in cat <test?

    – Kusalananda
    Apr 5 at 9:14











  • Do you mean that “<filename” like input something "eof".not "enter"?

    – Jack Walter
    Apr 6 at 2:42

















  • If <test ran the shell commands in test, then how would one be able to redirect the contents of a file into a command, as in cat <test?

    – Kusalananda
    Apr 5 at 9:14











  • Do you mean that “<filename” like input something "eof".not "enter"?

    – Jack Walter
    Apr 6 at 2:42
















If <test ran the shell commands in test, then how would one be able to redirect the contents of a file into a command, as in cat <test?

– Kusalananda
Apr 5 at 9:14





If <test ran the shell commands in test, then how would one be able to redirect the contents of a file into a command, as in cat <test?

– Kusalananda
Apr 5 at 9:14













Do you mean that “<filename” like input something "eof".not "enter"?

– Jack Walter
Apr 6 at 2:42





Do you mean that “<filename” like input something "eof".not "enter"?

– Jack Walter
Apr 6 at 2:42










1 Answer
1






active

oldest

votes


















3














In Bash, and some other shells, `<test` is a shorthand for the equivalent of `cat test`:




The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).




(the same is true for `...`-style command substitution).



That means that your command



$ `<test`


is the same as



$ `cat test`


- that is, insert the contents of the test file onto the command line in place of the command substitution expression and then, since it's then at the start of the command, execute the result with the first word as the command name.




On the other hand,



$ <test


is just an empty command with its standard input redirected from the test file, in any POSIX-like shell. It is essentially the same as : <test: does nothing and succeeds. That's not very useful, but it will raise an error if test doesn't exist or isn't readable.



The reverse direction, >test, will create or truncate test, and is sometimes useful.




The special behaviour of `<test` and $(<test) in Bash, zsh, ksh, etc is inconsistent with the way command substitution generally replicates the ordinary behaviour of the same command. It's a convenience and performance feature for the sake of commands like



printf '%s@%sn' $(<username.txt) $(<host.txt)


that want to read file contents into the command line, and get to save an extra process (by not spawning cat and letting the shell read the file itself).



The difference isn't anything to do with Enter or anything else like that - it's just a special case. I wouldn't recommend using $(<file) to execute a file: use . or source or some similar method instead that says what you're doing (even eval if it really comes to it). I wouldn't even recommend using $(<file) at all unless you're really sure you're in a tight loop where spawning an extra cat process mattered, because it's uncommon enough that people will be confused in exactly the way you were here.






share|improve this answer























  • thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

    – Jack Walter
    Apr 5 at 9:11











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



);






Jack Walter 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%2f510654%2fwhy-does-filename-not-run-the-cmd-from-filename-but-filename-and-execf%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









3














In Bash, and some other shells, `<test` is a shorthand for the equivalent of `cat test`:




The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).




(the same is true for `...`-style command substitution).



That means that your command



$ `<test`


is the same as



$ `cat test`


- that is, insert the contents of the test file onto the command line in place of the command substitution expression and then, since it's then at the start of the command, execute the result with the first word as the command name.




On the other hand,



$ <test


is just an empty command with its standard input redirected from the test file, in any POSIX-like shell. It is essentially the same as : <test: does nothing and succeeds. That's not very useful, but it will raise an error if test doesn't exist or isn't readable.



The reverse direction, >test, will create or truncate test, and is sometimes useful.




The special behaviour of `<test` and $(<test) in Bash, zsh, ksh, etc is inconsistent with the way command substitution generally replicates the ordinary behaviour of the same command. It's a convenience and performance feature for the sake of commands like



printf '%s@%sn' $(<username.txt) $(<host.txt)


that want to read file contents into the command line, and get to save an extra process (by not spawning cat and letting the shell read the file itself).



The difference isn't anything to do with Enter or anything else like that - it's just a special case. I wouldn't recommend using $(<file) to execute a file: use . or source or some similar method instead that says what you're doing (even eval if it really comes to it). I wouldn't even recommend using $(<file) at all unless you're really sure you're in a tight loop where spawning an extra cat process mattered, because it's uncommon enough that people will be confused in exactly the way you were here.






share|improve this answer























  • thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

    – Jack Walter
    Apr 5 at 9:11















3














In Bash, and some other shells, `<test` is a shorthand for the equivalent of `cat test`:




The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).




(the same is true for `...`-style command substitution).



That means that your command



$ `<test`


is the same as



$ `cat test`


- that is, insert the contents of the test file onto the command line in place of the command substitution expression and then, since it's then at the start of the command, execute the result with the first word as the command name.




On the other hand,



$ <test


is just an empty command with its standard input redirected from the test file, in any POSIX-like shell. It is essentially the same as : <test: does nothing and succeeds. That's not very useful, but it will raise an error if test doesn't exist or isn't readable.



The reverse direction, >test, will create or truncate test, and is sometimes useful.




The special behaviour of `<test` and $(<test) in Bash, zsh, ksh, etc is inconsistent with the way command substitution generally replicates the ordinary behaviour of the same command. It's a convenience and performance feature for the sake of commands like



printf '%s@%sn' $(<username.txt) $(<host.txt)


that want to read file contents into the command line, and get to save an extra process (by not spawning cat and letting the shell read the file itself).



The difference isn't anything to do with Enter or anything else like that - it's just a special case. I wouldn't recommend using $(<file) to execute a file: use . or source or some similar method instead that says what you're doing (even eval if it really comes to it). I wouldn't even recommend using $(<file) at all unless you're really sure you're in a tight loop where spawning an extra cat process mattered, because it's uncommon enough that people will be confused in exactly the way you were here.






share|improve this answer























  • thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

    – Jack Walter
    Apr 5 at 9:11













3












3








3







In Bash, and some other shells, `<test` is a shorthand for the equivalent of `cat test`:




The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).




(the same is true for `...`-style command substitution).



That means that your command



$ `<test`


is the same as



$ `cat test`


- that is, insert the contents of the test file onto the command line in place of the command substitution expression and then, since it's then at the start of the command, execute the result with the first word as the command name.




On the other hand,



$ <test


is just an empty command with its standard input redirected from the test file, in any POSIX-like shell. It is essentially the same as : <test: does nothing and succeeds. That's not very useful, but it will raise an error if test doesn't exist or isn't readable.



The reverse direction, >test, will create or truncate test, and is sometimes useful.




The special behaviour of `<test` and $(<test) in Bash, zsh, ksh, etc is inconsistent with the way command substitution generally replicates the ordinary behaviour of the same command. It's a convenience and performance feature for the sake of commands like



printf '%s@%sn' $(<username.txt) $(<host.txt)


that want to read file contents into the command line, and get to save an extra process (by not spawning cat and letting the shell read the file itself).



The difference isn't anything to do with Enter or anything else like that - it's just a special case. I wouldn't recommend using $(<file) to execute a file: use . or source or some similar method instead that says what you're doing (even eval if it really comes to it). I wouldn't even recommend using $(<file) at all unless you're really sure you're in a tight loop where spawning an extra cat process mattered, because it's uncommon enough that people will be confused in exactly the way you were here.






share|improve this answer













In Bash, and some other shells, `<test` is a shorthand for the equivalent of `cat test`:




The command substitution $(cat file) can be replaced by the equivalent but faster $(< file).




(the same is true for `...`-style command substitution).



That means that your command



$ `<test`


is the same as



$ `cat test`


- that is, insert the contents of the test file onto the command line in place of the command substitution expression and then, since it's then at the start of the command, execute the result with the first word as the command name.




On the other hand,



$ <test


is just an empty command with its standard input redirected from the test file, in any POSIX-like shell. It is essentially the same as : <test: does nothing and succeeds. That's not very useful, but it will raise an error if test doesn't exist or isn't readable.



The reverse direction, >test, will create or truncate test, and is sometimes useful.




The special behaviour of `<test` and $(<test) in Bash, zsh, ksh, etc is inconsistent with the way command substitution generally replicates the ordinary behaviour of the same command. It's a convenience and performance feature for the sake of commands like



printf '%s@%sn' $(<username.txt) $(<host.txt)


that want to read file contents into the command line, and get to save an extra process (by not spawning cat and letting the shell read the file itself).



The difference isn't anything to do with Enter or anything else like that - it's just a special case. I wouldn't recommend using $(<file) to execute a file: use . or source or some similar method instead that says what you're doing (even eval if it really comes to it). I wouldn't even recommend using $(<file) at all unless you're really sure you're in a tight loop where spawning an extra cat process mattered, because it's uncommon enough that people will be confused in exactly the way you were here.







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 5 at 8:48









Michael HomerMichael Homer

50.7k8140177




50.7k8140177












  • thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

    – Jack Walter
    Apr 5 at 9:11

















  • thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

    – Jack Walter
    Apr 5 at 9:11
















thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

– Jack Walter
Apr 5 at 9:11





thanks for u reply.i know the correct way.i wannna know the difference between keyboard input and file input. So $<test equals type Enter directly?@Michael Homer

– Jack Walter
Apr 5 at 9:11










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









draft saved

draft discarded


















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












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











Jack Walter 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%2f510654%2fwhy-does-filename-not-run-the-cmd-from-filename-but-filename-and-execf%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







RHfNTvw,BH97RkOjmW0bQPjZ,P9yMkJdvdTTT,ie BbtG
vzAa7Gd,0BReG3Gi0wBLw,rk5r

Popular posts from this blog

getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

NetworkManager fails with “Could not find source connection”Trouble connecting to VPN using network-manager, while command line worksHow can I be notified about state changes to a VPN adapterBacktrack 5 R3 - Refuses to connect to VPNFeed all traffic through OpenVPN for a specific network namespace onlyRun daemon on startup in Debian once openvpn connection establishedpfsense tcp connection between openvpn and lan is brokenInternet connection problem with web browsers onlyWhy does NetworkManager explicitly support tun/tap devices?Browser issues with VPNTwo IP addresses assigned to the same network card - OpenVPN issues?Cannot connect to WiFi with nmcli, although secrets are provided

Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.