[Solved] Sourcing in Konsole Subshell gives Syntax Errors

For discussions about programming and projects not necessarily associated with Porteus.
User avatar
Rava
Contributor
Contributor
Posts: 5424
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#16 by Rava » 04 May 2015, 04:28

Just realized, I can edit the initial post, but I don't see any button for moving a thread into another sub-forum... Do I just miss that, or is that something only admins can do?


I use custom colours in palemoon, disallowing all sites to use their own colours, and some sites, like phpBB and others have a bug, and all links like [mit Zitat antworten] [Information] or [Benutzer verwarnen] are plain and only black buttons on black background. I have to know where the links are, more or less, hovering the mouse there gives me the popup info if I am hovering at the right button, or not. Then I can e.g. "reply with quote" </non Porteus bug>
So, it can happen that I miss links, cause having issues seeing completely black buttons on black background. =@
Cheers!
Yours Rava

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 4095
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#17 by ncmprhnsbl » 04 May 2015, 05:36

but I don't see any button for moving a thread into another sub-forum...
bottom right hand page corner is 'quick mod tools', a box saying 'lock topic' and a 'go' button
click on 'lock topic' and a drop down menu with more options appears...including move topic
not entirely obvious even when you can see it..
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Rava
Contributor
Contributor
Posts: 5424
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#18 by Rava » 04 May 2015, 09:15

ncmprhnsbl wrote:bottom right hand page corner is 'quick mod tools', a box saying 'lock topic' and a 'go' button
click on 'lock topic' and a drop down menu with more options appears...including move topic
not entirely obvious even when you can see it..
Sounds like I have to temporarily switch all pages to allow/show their own colours (like, once again <le regular yawn>), then I sure will see it.

... But it's a good mind training, when I have to recall the unseen, hidden exact location of yet another hidden buttons to be used regularly... Yay for brain training!
Cheers!
Yours Rava

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#19 by Bogomips » 04 May 2015, 12:33

Another Way: Viewing topic > Moderator Control Panel > Moderate Topic 8)
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Rava
Contributor
Contributor
Posts: 5424
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#20 by Rava » 04 May 2015, 17:08

Moved thread to "programming", since it is about script coding, and not about KDE. :)
Cheers!
Yours Rava

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Very Similar Subshell Bug

Post#21 by Bogomips » 25 Aug 2016, 20:54

Code: Select all

uest@porteus:~$ sh mksavfile.sh
mksavfile.sh: line 36: syntax error near unexpected token `<'
mksavfile.sh: line 36: `	read used < <(df -BM --output=used  $u|tail -n1); usd0=${used%M};'
guest@porteus:~$ chmod a+x mksavfile.sh 
guest@porteus:~$ mksavfile.sh
bash: mksavfile.sh: command not found
guest@porteus:~$ ./mksavfile.sh 
Usage:		sh mksavfile.sh 	[/Path/to/]Savefile  [ <Size of file in MB>  [ Block size for XFS ] ]
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#22 by Bogomips » 13 Oct 2016, 12:27

Resolved
  • !st Issue

    Code: Select all

    guest@porteus:~$ echo PID of Shell: $$
    PID of Shell: 2484
    guest@porteus:~$ mkdir pk01
    guest@porteus:~$ cd pk01/
    guest@porteus:~/pk01$ sh
    guest@porteus:~/pk01$ . ../p10/Por/Komodo/funcs.sh
    sh: ../p10/Por/Komodo/pakdep.sh: line 208: syntax error near unexpected token `<'
    sh: ../p10/Por/Komodo/pakdep.sh: line 208: `  readarray -t req   < <( cat reqmts )'
    sh: ../p10/Por/Komodo/pak.sh: line 37: syntax error near unexpected token `<'
    sh: ../p10/Por/Komodo/pak.sh: line 37: `  readarray -t vec < <(cat ${1%.pak}.pak)	# Allow for auto-completion	2015-04-25 17:05:03'
    sh: ../p10/Por/Komodo/selpak.sh: line 29: syntax error near unexpected token `<'
    sh: ../p10/Por/Komodo/selpak.sh: line 29: `  readarray -t rps   < <( cat ${rq}_ar.rep )'
    guest@porteus:~/pk01$ exit
    
    guest@porteus:~/pk01$ echo PID of Shell: $$
    PID of Shell: 2484
    guest@porteus:~/pk01$ bash
    guest@porteus:~/pk01$ echo PID of Shell: $$
    PID of Shell: 2645
    guest@porteus:~/pk01$ . ../p10/Por/Komodo/funcs.sh
    guest@porteus:~/pk01$ exit
    
  • 2nd Issue

    Code: Select all

    guest@porteus:~$ sh mksavfile.sh 
    mksavfile.sh: line 38: syntax error near unexpected token `<'
    mksavfile.sh: line 38: `	read used < <(df -BM --output=used  $u|tail -n1); usd0=${used%M};'
    
    guest@porteus:~$ bash mksavfile.sh 
    Usage:	mksavfile.sh	[/Path/to/]Savefile [<Size of file in MB>[Block size for XFS]]
    
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

port
Samurai
Samurai
Posts: 137
Joined: 18 Feb 2016, 09:25
Distribution: Linux porteus 3.2.2 KDE
Location: Spain

Re: Sourcing from Konsole Subshell results in Syntax Errors

Post#23 by port » 13 Oct 2016, 17:57

Rava wrote:
Bogomips wrote:Think there has been a bit of a misunderstanding here. What I meant was that I got the instruction from the Internet, and which I'm now using in my script. Not sure if this is the exact url, but the statement is very much the same

Code: Select all

$ read test < <(echo hello world)
$ echo $test
hello world
It's answer #14 at http://stackoverflow.com/questions/2746 ... stdin-pipe
Ohhhhh I see, now that's something new to me... I have to find other occurences of that very syntax to fully understand it... *le dramatic sigh*
for your interest if any, that syntax is called process substitution and in simply words it works providing the result of command execution (input if >() or output if <()) as a file you can use in place of any common file, in particular in shell redirection

so, a command like

Code: Select all

$ cat <(ls /)
allows you to show the contents of the root directory (directory listing, ls), as the same way you display the content of any other common file such as cat ~/.bashrc

You may wonder how it works or exactly what file are you displaying with that command, the answer is you're display a temporary file, that's how it works:

Code: Select all

$ echo <(ls /)
/proc/self/fd/11
so when invoking cat <(ls) you are displaying the contents of temporary file /proc/self/fd/11 It's exactly the same mechanism of named pipes but it's done authomatically by the shell

You may wonder if it is these two command are the same:

Code: Select all

$ cat <( ls )
$ ls | cat 
and the answer is almost the same, the result for both commands is the same, you show the listing of current directory, but the first one uses the same shell for the only process while the latter uses two subshells one for each command which is slighty but important difference.

Of course you can use it also combined with redirection:

Code: Select all

$ cat | tr ' ' '-'
var name with spaces
var-name-with-spaces
$ tr ' ' '-' < <(cat)
var name with spaces
var-name-with-spaces

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: [Solved] Sourcing in Konsole Subshell gives Syntax Error

Post#24 by Bogomips » 13 Oct 2016, 19:38

Code: Select all

guest@porteus:~$ read s <(ls)
bash: read: `/dev/fd/63': not a valid identifier

guest@porteus:~$ echo <(ls)
/dev/fd/63
guest@porteus:~$ echo <(ls /)
/dev/fd/63
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

port
Samurai
Samurai
Posts: 137
Joined: 18 Feb 2016, 09:25
Distribution: Linux porteus 3.2.2 KDE
Location: Spain

Re: [Solved] Sourcing in Konsole Subshell gives Syntax Error

Post#25 by port » 14 Oct 2016, 03:22

Bogomips wrote:

Code: Select all

guest@porteus:~$ read s <(ls)
bash: read: `/dev/fd/63': not a valid identifier

guest@porteus:~$ echo <(ls)
/dev/fd/63
guest@porteus:~$ echo <(ls /)
/dev/fd/63
read command reads from standard input not from file, so the right syntax for your command is:

Code: Select all

$ ls
amp.fzz     fossil           PCB.00006003.backup 
$ read s < <(ls)
$ echo $s
amp.fzz
remember that process substitution may be replaced by a common file so if you need file redirection you must include redirection operator as well

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: [Solved] Sourcing in Konsole Subshell gives Syntax Error

Post#26 by Bogomips » 14 Oct 2016, 12:22

@port
Thanks for the heads up on process substitution being replaced by a temporary file.

The aim here was to show this best illustrated by the error message:

Code: Select all

guest@porteus:~$ read s <(ls)
bash: read: `/dev/fd/63': not a valid identifier
:)
Process Substitution
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of <(list) or >(list). The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.

When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion.
Last edited by Bogomips on 14 Oct 2016, 18:47, edited 1 time in total.
Reason: Manual Extract
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

port
Samurai
Samurai
Posts: 137
Joined: 18 Feb 2016, 09:25
Distribution: Linux porteus 3.2.2 KDE
Location: Spain

Re: [Solved] Sourcing in Konsole Subshell gives Syntax Error

Post#27 by port » 15 Oct 2016, 05:44

@Bogomips you're welcome I was just trying to introduce an easy image to remember the right use of process substitution ;)
Bogomips wrote: The aim here was to show this best illustrated by the error message:

Code: Select all

guest@porteus:~$ read s <(ls)
bash: read: `/dev/fd/63': not a valid identifier
:)
Process Substitution
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of <(list) or >(list). The process list is run with its input or output connected to a FIFO or some file in /dev/fd. The name of this file is passed as an argument to the current command as the result of the expansion. If the >(list) form is used, writing to the file will provide input for list. If the <(list) form is used, the file passed as an argument should be read to obtain the output of list.

When available, process substitution is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion.
yes, that's the point, for that reason I said it's the same as named pipes but done automathically by the sell, very well explained in that quote ;)

Post Reply