How to determine if result of process substitution is a file pathProblem understanding 'hash' command in a .sh fileSome puzzles of how to close file descriptors on sh or bashHow do I test if a file does not exist using ZSH?Preform operation in bash only if a variable is less than a second variableHow do I pass a file path to a function instead of the contents of the file?read a file from Server path - bashConditional process substitutionstderr redirection by reading a fileHow does (echo 'text' ; cat file.txt ) > new file.txt actually work?How to use an escaped file-name string saved within a bash variable in a new shell command?

How long should I wait to plug in my refrigerator after unplugging it?

Overprovisioning SSD on ubuntu. How? Ubuntu 19.04 Samsung SSD 860

Is this popular optical illusion made of a grey-scale image with coloured lines?

Is Illustrator accurate for business card sizes?

Can it be useful for a player block with a hanging piece in a back rank mate situation?

Is the EU really banning "toxic propellants" in 2020? How is that going to work?

Is the un-detonated globe of Otiluke's Freezing Sphere magical?

Matrix condition number and reordering

How did Biff return to 2015 from 1955 without a lightning strike?

How to structure presentation to avoid getting questions that will be answered later in the presentation?

UX writing: When to use "we"?

"Will flex for food". What does this phrase mean?

Feedback diagram

Why have both: BJT and FET transistors on IC output?

Why are Star Wars Rebel Alliance ships named after letters from the Latin alphabet?

Has J.J.Jameson ever found out that Peter Parker is Spider-Man?

Can I shorten this filter, that finds disk sizes over 100G?

linearization of objective function

Declaring a visitor to the UK as my "girlfriend" - effect on getting a Visitor visa?

Is law enforcement responcible for damages made by a search warrent?

Is Norway in the Single Market?

Pre-Greek θάλασσα "thalassa" and Turkish talaz

Why do player start with fighting for the corners in go?

Map vs. Table for index-specific operations on 2D arrays



How to determine if result of process substitution is a file path


Problem understanding 'hash' command in a .sh fileSome puzzles of how to close file descriptors on sh or bashHow do I test if a file does not exist using ZSH?Preform operation in bash only if a variable is less than a second variableHow do I pass a file path to a function instead of the contents of the file?read a file from Server path - bashConditional process substitutionstderr redirection by reading a fileHow does (echo 'text' ; cat file.txt ) > new file.txt actually work?How to use an escaped file-name string saved within a bash variable in a new shell command?






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








1















If I do this:



echo <(cat)


I get:



/dev/fd/63


so say at the command line I have:



myapp -f <(cat)


when I run it I get this error:




You need to pass a file after the -f flag. The resolved file path was:
'/dev/fd/63'. This path did not appear to exist on the filesystem.




How can I determine if the result of the process substitution is an actual file (for validation purposes)? Here is my bash code which generated the error:



 if [[ -L "$file_path" ]]; then
file_path="$(readlink "$file_path")";
fi

if [[ ! -f "$file_path" ]]; then
echo "You need to pass a file after the -f flag. The resolved file path was: '$file_path'. This path did not appear to exist on the filesystem".;
return 1;
fi


if I get rid of my validation, code, I get this:




Could not open the following file for reading: /dev/fd/63 EBADF: bad
file descriptor, open '/dev/fd/63'




The node.js code I am using to read from the path is:



const fd = fs.openSync(file_path, 'r');
fs.read(fd, ...);









share|improve this question





















  • 2





    [ -f file ] tests if file is a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a /dev/fd/n -> /proc/self/fd/n "symlink" is some informative string like type:[inum], not a path for pipes, sockets, etc.

    – mosvy
    8 hours ago












  • so much for everything is a file lulz..anyway I just want to be able to read from /dev/fd/x, is there some way to do that?

    – Alexander Mills
    7 hours ago






  • 1





    maybe you should post a complete example; node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null) works for me.

    – mosvy
    7 hours ago






  • 1





    But simply cat <(cat) will not work from console, because the cat inside the process substitution may run in a different process group than the foreground one, and cannot read from the tty.

    – mosvy
    7 hours ago






  • 1





    I don't have a MacOS system. But someone else may have, so post a complete reproducible testcase. FWIW, on BSD, /dev/fd/N are character special files (they aren't regular files, either). And on FreeBSD you should mount fdescfs if you want to access filedescs > 2 via /dev/fd/N.

    – mosvy
    7 hours ago


















1















If I do this:



echo <(cat)


I get:



/dev/fd/63


so say at the command line I have:



myapp -f <(cat)


when I run it I get this error:




You need to pass a file after the -f flag. The resolved file path was:
'/dev/fd/63'. This path did not appear to exist on the filesystem.




How can I determine if the result of the process substitution is an actual file (for validation purposes)? Here is my bash code which generated the error:



 if [[ -L "$file_path" ]]; then
file_path="$(readlink "$file_path")";
fi

if [[ ! -f "$file_path" ]]; then
echo "You need to pass a file after the -f flag. The resolved file path was: '$file_path'. This path did not appear to exist on the filesystem".;
return 1;
fi


if I get rid of my validation, code, I get this:




Could not open the following file for reading: /dev/fd/63 EBADF: bad
file descriptor, open '/dev/fd/63'




The node.js code I am using to read from the path is:



const fd = fs.openSync(file_path, 'r');
fs.read(fd, ...);









share|improve this question





















  • 2





    [ -f file ] tests if file is a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a /dev/fd/n -> /proc/self/fd/n "symlink" is some informative string like type:[inum], not a path for pipes, sockets, etc.

    – mosvy
    8 hours ago












  • so much for everything is a file lulz..anyway I just want to be able to read from /dev/fd/x, is there some way to do that?

    – Alexander Mills
    7 hours ago






  • 1





    maybe you should post a complete example; node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null) works for me.

    – mosvy
    7 hours ago






  • 1





    But simply cat <(cat) will not work from console, because the cat inside the process substitution may run in a different process group than the foreground one, and cannot read from the tty.

    – mosvy
    7 hours ago






  • 1





    I don't have a MacOS system. But someone else may have, so post a complete reproducible testcase. FWIW, on BSD, /dev/fd/N are character special files (they aren't regular files, either). And on FreeBSD you should mount fdescfs if you want to access filedescs > 2 via /dev/fd/N.

    – mosvy
    7 hours ago














1












1








1








If I do this:



echo <(cat)


I get:



/dev/fd/63


so say at the command line I have:



myapp -f <(cat)


when I run it I get this error:




You need to pass a file after the -f flag. The resolved file path was:
'/dev/fd/63'. This path did not appear to exist on the filesystem.




How can I determine if the result of the process substitution is an actual file (for validation purposes)? Here is my bash code which generated the error:



 if [[ -L "$file_path" ]]; then
file_path="$(readlink "$file_path")";
fi

if [[ ! -f "$file_path" ]]; then
echo "You need to pass a file after the -f flag. The resolved file path was: '$file_path'. This path did not appear to exist on the filesystem".;
return 1;
fi


if I get rid of my validation, code, I get this:




Could not open the following file for reading: /dev/fd/63 EBADF: bad
file descriptor, open '/dev/fd/63'




The node.js code I am using to read from the path is:



const fd = fs.openSync(file_path, 'r');
fs.read(fd, ...);









share|improve this question
















If I do this:



echo <(cat)


I get:



/dev/fd/63


so say at the command line I have:



myapp -f <(cat)


when I run it I get this error:




You need to pass a file after the -f flag. The resolved file path was:
'/dev/fd/63'. This path did not appear to exist on the filesystem.




How can I determine if the result of the process substitution is an actual file (for validation purposes)? Here is my bash code which generated the error:



 if [[ -L "$file_path" ]]; then
file_path="$(readlink "$file_path")";
fi

if [[ ! -f "$file_path" ]]; then
echo "You need to pass a file after the -f flag. The resolved file path was: '$file_path'. This path did not appear to exist on the filesystem".;
return 1;
fi


if I get rid of my validation, code, I get this:




Could not open the following file for reading: /dev/fd/63 EBADF: bad
file descriptor, open '/dev/fd/63'




The node.js code I am using to read from the path is:



const fd = fs.openSync(file_path, 'r');
fs.read(fd, ...);






bash shell test read fd






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago







Alexander Mills

















asked 8 hours ago









Alexander MillsAlexander Mills

2,4642 gold badges21 silver badges67 bronze badges




2,4642 gold badges21 silver badges67 bronze badges










  • 2





    [ -f file ] tests if file is a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a /dev/fd/n -> /proc/self/fd/n "symlink" is some informative string like type:[inum], not a path for pipes, sockets, etc.

    – mosvy
    8 hours ago












  • so much for everything is a file lulz..anyway I just want to be able to read from /dev/fd/x, is there some way to do that?

    – Alexander Mills
    7 hours ago






  • 1





    maybe you should post a complete example; node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null) works for me.

    – mosvy
    7 hours ago






  • 1





    But simply cat <(cat) will not work from console, because the cat inside the process substitution may run in a different process group than the foreground one, and cannot read from the tty.

    – mosvy
    7 hours ago






  • 1





    I don't have a MacOS system. But someone else may have, so post a complete reproducible testcase. FWIW, on BSD, /dev/fd/N are character special files (they aren't regular files, either). And on FreeBSD you should mount fdescfs if you want to access filedescs > 2 via /dev/fd/N.

    – mosvy
    7 hours ago













  • 2





    [ -f file ] tests if file is a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a /dev/fd/n -> /proc/self/fd/n "symlink" is some informative string like type:[inum], not a path for pipes, sockets, etc.

    – mosvy
    8 hours ago












  • so much for everything is a file lulz..anyway I just want to be able to read from /dev/fd/x, is there some way to do that?

    – Alexander Mills
    7 hours ago






  • 1





    maybe you should post a complete example; node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null) works for me.

    – mosvy
    7 hours ago






  • 1





    But simply cat <(cat) will not work from console, because the cat inside the process substitution may run in a different process group than the foreground one, and cannot read from the tty.

    – mosvy
    7 hours ago






  • 1





    I don't have a MacOS system. But someone else may have, so post a complete reproducible testcase. FWIW, on BSD, /dev/fd/N are character special files (they aren't regular files, either). And on FreeBSD you should mount fdescfs if you want to access filedescs > 2 via /dev/fd/N.

    – mosvy
    7 hours ago








2




2





[ -f file ] tests if file is a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a /dev/fd/n -> /proc/self/fd/n "symlink" is some informative string like type:[inum], not a path for pipes, sockets, etc.

– mosvy
8 hours ago






[ -f file ] tests if file is a regular file, and the file created by a process substitution is a pipe, not a regular file. Also, on Linux, the target of a /dev/fd/n -> /proc/self/fd/n "symlink" is some informative string like type:[inum], not a path for pipes, sockets, etc.

– mosvy
8 hours ago














so much for everything is a file lulz..anyway I just want to be able to read from /dev/fd/x, is there some way to do that?

– Alexander Mills
7 hours ago





so much for everything is a file lulz..anyway I just want to be able to read from /dev/fd/x, is there some way to do that?

– Alexander Mills
7 hours ago




1




1





maybe you should post a complete example; node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null) works for me.

– mosvy
7 hours ago





maybe you should post a complete example; node -e 'fs=require("fs"); fs.openSync(process.argv[1], "r")' <(cat /dev/null) works for me.

– mosvy
7 hours ago




1




1





But simply cat <(cat) will not work from console, because the cat inside the process substitution may run in a different process group than the foreground one, and cannot read from the tty.

– mosvy
7 hours ago





But simply cat <(cat) will not work from console, because the cat inside the process substitution may run in a different process group than the foreground one, and cannot read from the tty.

– mosvy
7 hours ago




1




1





I don't have a MacOS system. But someone else may have, so post a complete reproducible testcase. FWIW, on BSD, /dev/fd/N are character special files (they aren't regular files, either). And on FreeBSD you should mount fdescfs if you want to access filedescs > 2 via /dev/fd/N.

– mosvy
7 hours ago






I don't have a MacOS system. But someone else may have, so post a complete reproducible testcase. FWIW, on BSD, /dev/fd/N are character special files (they aren't regular files, either). And on FreeBSD you should mount fdescfs if you want to access filedescs > 2 via /dev/fd/N.

– mosvy
7 hours ago











1 Answer
1






active

oldest

votes


















3














To determine, in Bash, whether a string value is a path on your current system, use [[ -e "$path" ]]. This checks whether the path exists, and doesn't make any assumptions about the type of file it points to.






share|improve this answer

























  • this definitely helps, thanks

    – Alexander Mills
    7 hours 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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f533742%2fhow-to-determine-if-result-of-process-substitution-is-a-file-path%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














To determine, in Bash, whether a string value is a path on your current system, use [[ -e "$path" ]]. This checks whether the path exists, and doesn't make any assumptions about the type of file it points to.






share|improve this answer

























  • this definitely helps, thanks

    – Alexander Mills
    7 hours ago















3














To determine, in Bash, whether a string value is a path on your current system, use [[ -e "$path" ]]. This checks whether the path exists, and doesn't make any assumptions about the type of file it points to.






share|improve this answer

























  • this definitely helps, thanks

    – Alexander Mills
    7 hours ago













3












3








3







To determine, in Bash, whether a string value is a path on your current system, use [[ -e "$path" ]]. This checks whether the path exists, and doesn't make any assumptions about the type of file it points to.






share|improve this answer













To determine, in Bash, whether a string value is a path on your current system, use [[ -e "$path" ]]. This checks whether the path exists, and doesn't make any assumptions about the type of file it points to.







share|improve this answer












share|improve this answer



share|improve this answer










answered 7 hours ago









l0b0l0b0

30.2k23 gold badges128 silver badges264 bronze badges




30.2k23 gold badges128 silver badges264 bronze badges















  • this definitely helps, thanks

    – Alexander Mills
    7 hours ago

















  • this definitely helps, thanks

    – Alexander Mills
    7 hours ago
















this definitely helps, thanks

– Alexander Mills
7 hours ago





this definitely helps, thanks

– Alexander Mills
7 hours ago

















draft saved

draft discarded
















































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%2f533742%2fhow-to-determine-if-result-of-process-substitution-is-a-file-path%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







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單