Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 19 Jun 2018, 20:38
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Code not working in init script of initrd.gz. (Solved)
Post new topic   Reply to topic View previous topic :: View next topic
Page 2 of 2 [22 Posts]   Goto page: Previous 1, 2
Author Message
technosaurus


Joined: 18 May 2008
Posts: 4819
Location: Kingwood, TX

PostPosted: Sat 13 Dec 2014, 09:31    Post subject:  

LazY Puppy wrote:
I did never write or quote: OLDWP2=${OLDWP:1:nlen-2} #, all my codes are without the #. Unless I might be blind, so w(here)tf did you get this?
That was my comment, you can't just go throwing expressions around like that and expect it to work in a posix compliant shell. (Ubuntu had a page called "/bin/sh is dash" or something with a lot of portability tips)
For portability, whenever you do math, either use expr or enclose it in $(()) ... and for maximum portability, spell out things like i=$((i+1)) rather than simply doing i++, because even that is not widely supported.

_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Sat 13 Dec 2014, 13:27    Post subject:  

Quote:
That was my comment,

Ok, I see now.

Since the '<-' did point to the '#' I just did not understand that you were made this comment.

Explanation how I do read forums '[ quote ]' (1) and forums '[ code ]' (2):

- I'm reading (1) as 'quoted text' besides
- I'm reading (2) as 'quoted (already existing) code'

Quote:
you can't just go throwing expressions around like that and expect it to work in a posix compliant shell. (Ubuntu had a page called "/bin/sh is dash" or something with a lot of portability tips)

I found this in my early days when creating one of the first version of LazY Puppy and it has worked for me in all of my several LazY Puppy Systems (e.g. derivatives of Lucid 528, Precise 56 & 571, Three Headed Dog, MacPup 528, LxPup 12.x and Carolina 1.2) until I was stumbling over the issue in init script, which was the first time this didn't work. If I remember correctly this came out of a script by SFR, who is known to me as a more expert in bash than myself ever will be. So there was no reason to me why NOT to trust and NOT to use it.

Quote:
For portability, whenever you do math, either use expr or enclose it in $(()) ... and for maximum portability, spell out things like i=$((i+1)) rather than simply doing i++, because even that is not widely supported.

When it comes to increase or decrease contents of a variable I usually use this:
Code:
i=$(( i + 1 ))

instead of doing i++, since I've stumbled a few times and found this not working. Sometimes I used combinations of i=$(( i + 1 )) and i++ when i++ seems not to work. Laughing

So compatibility.

What for compatibility?
Where might this conflict (I 'develop' for Puppy only, not for other OS that is using bash)?

By this now it's just proven once again that I'm NOT a programmer and rather being a Hacker having fun in Puppy Linux.

How shall I ever getting able to perform patches for WoofCE and getting some of my -hopefully somehow innovative work- into WoofCE or just a newer Puppy, with such a less amount of Bash knowledge? Sad

Btw: I have made a quick search for :nlen in /usr/local (where I put my bash applications usually) of my LazY Puppy and found 36 files where this is used. Since I do have also stuff in /usr/sbin, /usr/bin, /etc/xdg/openbox and /root/my-applications this number may increase up to 50 files - or even more. I have used this also like :flen or :bnlen, so it might increase once again.

Should I correct this in all my bash script applications?

Thanks for increasing my knowledge! Very Happy

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
greengeek


Joined: 20 Jul 2010
Posts: 5053
Location: Republic of Novo Zelande

PostPosted: Sat 13 Dec 2014, 14:52    Post subject:  

Very informative conversation. Just getting some links saved for my future reference:

http://people.fas.harvard.edu/~lib113/reference/unix/portable_scripting.html

https://wiki.ubuntu.com/DashAsBinSh

http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Portable-Shell.html#Portable-Shell
Back to top
View user's profile Send private message 
don570


Joined: 10 Mar 2010
Posts: 5056
Location: Ontario

PostPosted: Sat 13 Dec 2014, 15:13    Post subject:  

This page describes converting a bash script to dash

http://mywiki.wooledge.org/Bashism

______________________________________
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4819
Location: Kingwood, TX

PostPosted: Sat 13 Dec 2014, 20:27    Post subject:  

LazY Puppy wrote:
Should I correct this in all my bash script applications?
I wouldn't bother unless you want them to run ~8 times faster than with bash 4.x, just change the shabang to #!/bin/bash so that if anyone does want to use it with another shell (or code from it), they are hinted that they may have to do a bash-ectome. I normally put #!/bin/ash as the shabang while I am testing; then change it to #!/bin/sh when finished (not perfect, since ash does support some bashisms)
_________________
Check out my github repositories. I may eventually get around to updating my blogspot.
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 4208
Location: Kiel,Germany

PostPosted: Mon 15 Dec 2014, 13:54    Post subject:  

Just for the record :

In cygwin shell on Windows Vista :


User@User-PC ~
$ echo $BASH_VERSION
4.1.10(4)-release

User@User-PC ~
$ cd C:

User@User-PC /cygdrive/c
$ ls
$Recycle.Bin IO.SYS
autoexec.bat mbr.win.orig.bs1
Boot mbr.win.orig.bs512
bootmgr menu.lst
BOOTSECT.BAK menu.lst-Grub4dosMade
config.sys MSDOS.SYS


User@User-PC ~
$ A2=${A:1:nlen-2}

Works .

busybox ash would not support that syntax likely -
Lupu Puppy had still version 1.4.2 - not 1.14.2 or 1.40.2 ... of busybox

and that even did not understand ${STRING//delete_me_globally/} substitution i think and or ${STRING:fromX:toY}

just ${STRING%delete_me_at_the_end} and ${STRING#delete_me_at_the_beginning}
plus wildcard

Thats why the code looks a bit clumsy in the /init sometimes


I am Running scripts only as #!/bin/ash now - only use #!/bin/bash while transforming old code to ash to remind me weeks later why things are like they are .

bash invoked as #!/bin/sh should work different :
When invoked as sh, Bash enters POSIX mode after reading the startup files.
6.11 Bash POSIX Mode : http://www.gnu.org/software/bash/manual/bashref.html#Invoking-Bash

_________________
«Give me GUI or Death» -- I give you [[Xx]term[inal]] [[Cc]on[s][ole]] .
Macpup user since 2010 on full installations.
People who want problems with Puppy boot frugal Razz
Back to top
View user's profile Send private message 
LazY Puppy


Joined: 21 Nov 2014
Posts: 2007
Location: Germany

PostPosted: Mon 15 Dec 2014, 22:47    Post subject:  

technosaurus wrote:
I wouldn't bother unless you want them to run ~8 times faster than with bash 4.x, just change the shabang to #!/bin/bash so that if anyone does want to use it with another shell (or code from it), they are hinted that they may have to do a bash-ectome.

RSH wrote:
I usually start them with:
Code:
#!/bin/bash -a

_________________
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) Laughing

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! Wink
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 2 of 2 [22 Posts]   Goto page: Previous 1, 2
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0689s ][ Queries: 12 (0.0179s) ][ GZIP on ]