LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2023, 06:26 PM   #1
zeroone
LQ Newbie
 
Registered: Jul 2023
Posts: 13

Rep: Reputation: 0
Bash fail use file descriptor assigned a file that resides in /tmp


Does one experienced too that
Bash cannot use file descriptor assigned a file that resides in /tmp ?
i.e. inside script:
Code:
...
exec 3< <(/tmp/dls1)

while read -r -u3 f1; read -r f2
do
 # ...
done < <(cat /tmp/dls2)
...
output:
...

bash: /tmp/dls1: Permission denied


While the second file is read into f2 works. Please advise the wisest solution
 
Old 07-13-2023, 07:25 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Code:
exec 3< <(/tmp/dls1)
I have not tested your code but using process substitution for the redirect is probably the cause of your script not working. Instead try the following:
Code:
#!/bin/bash

while read -r f1 && read -r -u 3 f2
do
   echo "$f1 $f2"
done <"/tmp/dls1" 3<"/tmp/dls2"
I assume your user has read permissions for both files?

Last edited by michaelk; 07-14-2023 at 04:01 AM.
 
1 members found this post helpful.
Old 07-13-2023, 11:30 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP Are these synonyms or not? If not, what is the difference?
Code:
exec 3</tmp/dls1
exec 3< <(/tmp/dls1)
 
2 members found this post helpful.
Old 07-14-2023, 01:01 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,864

Rep: Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311Reputation: 7311
Quote:
Originally Posted by zeroone View Post
Bash cannot use file descriptor assigned a file that resides in /tmp ?
this is a definitely incorrect conclusion.

It can be a real permission issue (permission is really denied), but I think you missed the cat in the first line.
Code:
exec 3< <(cat /tmp/dls1)
But cat is not required at all (see uuoc), the previous suggestions are much better.

Additionally would be better to use shellcheck to catch errors like this.
 
1 members found this post helpful.
Old 07-14-2023, 04:17 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,715

Rep: Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899Reputation: 5899
Quote:
Originally Posted by NevemTeve View Post
@OP Are these synonyms or not? If not, what is the difference?
Code:
exec 3</tmp/dls1
exec 3< <(/tmp/dls1)
No, the first is a redirect and the second is process substitution. It isn't technically a syntax error so shellcheck will not report an error. I believe it fails because /tmp/dls1 isn't an executable and that as posted you are missing the cat command. Using process substitution is not required as I posted above.
 
Old 07-15-2023, 01:36 AM   #6
zeroone
LQ Newbie
 
Registered: Jul 2023
Posts: 13

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by NevemTeve View Post
@OP Are these synonyms or not? If not, what is the difference?
Code:
exec 3</tmp/dls1
exec 3< <(/tmp/dls1)
Solved by solution of your
Code:
exec 3</tmp/dls1
its synonym to corrected 2nd one: exec 3< <(cat /tmp/dls1)
 
Old 07-16-2023, 05:48 AM   #7
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,798

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Not a synonym,
but much more complex, and yes, with the same result.

Further, a lasting open with exec (until there is a close with another exec) is more complicated than redirecting a code block a la post#2
The loop is a code block; when redirected then the open occurs when the code block starts, and the close occurs when the code block ends.
BTW a { } forms a custom code block:
Code:
{
read line1
read line2
} </etc/group
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
which partition my file resides jolintan Linux - General 6 01-27-2022 10:50 AM
[SOLVED] How to allow OpenVPN (W10) client to use DNS server (BIND9) that resides on (Ubuntu 16.04) OpenVPN server? grigory Linux - Networking 13 09-17-2019 10:54 PM
[SOLVED] if [[ -n "$1" ]]; then FAIL FAIL FAIL rbees Programming 7 03-25-2015 02:39 PM
dvd has no URL assigned, so I can't play dvd's(no url assigned is the error message) Zych Linux - Newbie 3 08-01-2010 07:26 AM
difference between socket returned descriptor and accept returned descriptor naveenisback Programming 1 08-29-2009 04:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration