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?
Is law enforcement responcible for damages made by a search warrent?
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?
Gold Battle KoTH
Why have both: BJT and FET transistors on IC output?
linearization of objective function
How to get maximum number that newcount can hold?
How to avoid a lengthy conversation with someone from the neighborhood I don't share interests with
Is Norway in the Single Market?
A wiild aanimal, a cardinal direction, or a place by the water
Return last number in sub-sequences in a list of integers
Can I say "Gesundheit" if someone is coughing?
Plotting Chebyshev polynomials using PolarPlot and FilledCurve
How to structure presentation to avoid getting questions that will be answered later in the presentation?
Need help identifying how to open this bolt/screw
How do I safety check that there is no light in Darkroom / Darkbag?
Adding a (stair/baby) gate without facing walls
Is verification of a blockchain computationally cheaper than recreating it?
HackerRank Implement Queue using two stacks Solution
Is this popular optical illusion made of a grey-scale image with coloured lines?
Why do my fried eggs start browning very fast?
LWC component not rendering
Why do we need a voltage divider when we get the same voltage at the output as the input?
"Will flex for food". What does this phrase mean?
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;
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
|
show 2 more comments
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
2
[ -f file ]
tests iffile
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 liketype:[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
8 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 simplycat <(cat)
will not work from console, because thecat
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 mountfdescfs
if you want to access filedescs > 2 via/dev/fd/N
.
– mosvy
7 hours ago
|
show 2 more comments
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
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
bash shell test read fd
edited 9 hours ago
Alexander Mills
asked 9 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 iffile
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 liketype:[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
8 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 simplycat <(cat)
will not work from console, because thecat
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 mountfdescfs
if you want to access filedescs > 2 via/dev/fd/N
.
– mosvy
7 hours ago
|
show 2 more comments
2
[ -f file ]
tests iffile
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 liketype:[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
8 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 simplycat <(cat)
will not work from console, because thecat
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 mountfdescfs
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
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
8 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
|
show 2 more comments
1 Answer
1
active
oldest
votes
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.
this definitely helps, thanks
– Alexander Mills
7 hours ago
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%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
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.
this definitely helps, thanks
– Alexander Mills
7 hours ago
add a comment |
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.
this definitely helps, thanks
– Alexander Mills
7 hours ago
add a comment |
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.
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.
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
add a comment |
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
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%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
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
2
[ -f file ]
tests iffile
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 liketype:[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
8 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 thecat
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 mountfdescfs
if you want to access filedescs > 2 via/dev/fd/N
.– mosvy
7 hours ago