Post here if you are a new Porteus member and you're looking for some help.
-
Ed_P
- Contributor

- Posts: 8912
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#1
by Ed_P » 30 Nov 2015, 06:24
If the command "cat /proc/cmdline" returns a "from=" operand how does one extract the file name that follows it?
FileName=`cat /proc/cmdline`
echo "Boot File: ${FileName:17:36}"
Works if the filename is 36 characters but that isn't always the case. I've looked into using grep but have failed so far.

Ed_P
-
aus9
Post#2
by aus9 » 30 Nov 2015, 06:57
Ed_P
I am an intermediate coder so until you get a better reply I hope you don't mind me asking questions and making comments?
1) Can you show the actual output of these 2 commands please
The reason why I ask is your second line does not appear to be relative to your first line.
I was expecting your second line to read something like .....
echo $FileName | grep something or
VARIABLE2=`echo $FileName | grep something`
but maybe you are trying to write a script?
I don't know just guessing
good luck
aus9
-
donald
- Full of knowledge

- Posts: 2104
- Joined: 17 Jun 2013, 13:17
- Distribution: Porteus 3.2.2 XFCE 32bit
- Location: Germany
Post#3
by donald » 30 Nov 2015, 08:21
not using grep but sed to get the Filename
Try:
Code: Select all
cat /proc/cmdline | sed -e 's/^.*from=//' -e 's/ .*$//'
The first expression removes from= and everything before.
The second one removes the next space and everything after.
more info about sed
http://linux.die.net/man/1/sed
donald
-
Bogomips
- Full of knowledge

- Posts: 2564
- Joined: 25 Jun 2014, 15:21
- Distribution: 3.2.2 Cinnamon & KDE5
- Location: London
Post#4
by Bogomips » 30 Nov 2015, 12:26
Bashing along:
Code: Select all
guest@porteus:~$ c=$(cat /proc/cmdline); f=${c#*from=}; f=${f%% *}
guest@porteus:~$ echo $f
/tmp/iso/Por-KDE4-v3.1-4.2.5-i486.iso
@donald

Nice link.
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
-
Ed_P
- Contributor

- Posts: 8912
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#5
by Ed_P » 30 Nov 2015, 15:53
Wow!!!

Thank you all.
Code: Select all
guest@porteus:~$ cat /proc/cmdline
quiet from=/ISOs/Porteus-RazorQT-v3.0.1-x86_64-nu.iso changes=EXIT:/porteus3.0/changes/porteussave.dat extramod=/porteus3.0/Modules volume=40 reboot=cold ramsize=80%
guest@porteus:~$ echo $MODDIR
guest@porteus:~$ cat /proc/cmdline | sed -e 's/^.*from=//' -e 's/ .*$//'
/ISOs/Porteus-RazorQT-v3.0.1-x86_64-nu.iso
guest@porteus:~$ c=$(cat /proc/cmdline); f=${c#*from=}; f=${f%% *}
guest@porteus:~$ echo $f
/ISOs/Porteus-RazorQT-v3.0.1-x86_64-nu.iso
guest@porteus:~$
But the part that really blows my mind are the special character strings. c#* %% * s/^. s/.*$// Where did these come from??? The closest I remember seeing something close is here:
http://forum.porteus.org/viewtopic.php? ... =30#p28468
-update-
And now I have:
Code: Select all
guest@porteus:~$ bootdev.sh
Boot device: /dev/sda5
Device format: "ntfs"
Boot ISO: /ISOs/Porteus-RazorQT-v3.0.1-x86_64-nu.iso
Changes are being saved to a save.dat file.
Save.dat file: /porteus3.0/changes/porteussave.dat
Cmdline: quiet from=/ISOs/Porteus-RazorQT-v3.0.1-x86_64-nu.iso changes=EXIT:/porteus3.0/changes/porteussave.dat extramod=/porteus3.0/Modules volume=40 reboot=cold ramsize=80%
guest@porteus:~$

Ed_P
-
Bogomips
- Full of knowledge

- Posts: 2564
- Joined: 25 Jun 2014, 15:21
- Distribution: 3.2.2 Cinnamon & KDE5
- Location: London
Post#6
by Bogomips » 30 Nov 2015, 18:15
Ed_P wrote:But the part that really blows my mind are the special character strings. c#* %% * s/^. s/.*$// Where did these come from???
c#* %% *
http://man.cx/bashFind(^F): ##
s/^. s/.*$
http://manpages.ubuntu.com/manpages/pre ... gex.7.html
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
-
Ed_P
- Contributor

- Posts: 8912
- Joined: 06 Feb 2013, 22:12
- Distribution: Cinnamon 5.01 ISO
- Location: Western NY, USA
Post#7
by Ed_P » 30 Nov 2015, 23:55
Ed_P