| Author |
Message |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Thu 08 Dec 2011, 15:28 Post subject:
Question about Shell Script (#!/bin/sh) |
|
Hello,
I want to know how can i write multiple lines into a text file via "echo" (or is there another command existing)?
| Code: | | echo $scriptline >$isopname.files/build-script.sh |
writes one line into the text file '.../build-script.sh'. If i use this command again the text file '.../build-script.sh' will be deleted and the new line is written in the new text file '.../build-script.sh'.
How can i get multiple lines into the same text file?
Need it urgently!
RSH
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
vovchik

Joined: 23 Oct 2006 Posts: 1239 Location: Ukraine
|
Posted: Thu 08 Dec 2011, 15:50 Post subject:
|
|
Dear RSH,
It is simple and you almost have it. Just use the following:
| Code: | | echo $scriptline >>$isopname.files/build-script.sh |
Notice that the ">" symbol is doubled ">>", which means the information is appended without deleting the original.
With kind regards,
vovchik
|
|
Back to top
|
|
 |
sc0ttman

Joined: 16 Sep 2009 Posts: 2199 Location: UK
|
Posted: Thu 08 Dec 2011, 15:55 Post subject:
Re: Question about Shell Script (#!/bin/sh) |
|
IF I understand what you want correctly, | Code: | | echo $scriptline >$isopname.files/build-script.sh |
should simply be
| Code: | | echo "$scriptline" >> $isopname.files/build-script.sh | Note the >> which means 'append to the end of the file'...
Also, I added "" double quotes around $scriptline, in case in contains spaces or newlines
The double quotes mean that $scriptline can be more than one line...
| Code: | # VAR="hello
new line"
# echo $VAR
hello new line
# echo "$VAR"
hello
new line
#
|
Hope this helps... I'm sure others can help more...
EDIT: Just seen vovchiks reply, too...
_________________ Akita Linux, VLC-GTK, Pup Search, Pup File Search
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Thu 08 Dec 2011, 16:27 Post subject:
|
|
Hello!
Thank you for your fast reply.
| Quote: | It is simple and you almost have it. Just use the following.
Code:
echo $scriptline >>$isopname.files/build-script.sh |
Oh yes, i know i have seen this before in /usr/sbin/pfbpanel as i modified the menu of my puppy.
Why didn't i realized this?
Thank you very much again, vovchik and sc0ttman. Nice to have you (and the forum within all its members as well).
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2733 Location: Kiel,Germany
|
Posted: Thu 08 Dec 2011, 16:38 Post subject:
|
|
Another solution would be something like this using cat instead of echo :
# cat >>file.ext <<EOT
> #!/bin/sh
> echo "$0 START"
> echo "Now doing some code here"
> echo "$0" END
> EOT
# cat file.ext
#!/bin/sh
echo "/bin/bash START"
echo "Now doing some code here"
echo "/bin/bash" END
#
| Code: | cat >>file.ext <<EOT
#!/bin/sh
echo "$0 START"
echo "Now doing some code here"
echo "$0" END
EOT
|
'>' and '>>' works exactly the same as for echo .
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Fri 09 Dec 2011, 12:29 Post subject:
|
|
| Karl Godt wrote: | Another solution would be something like this using cat instead of echo :
# cat >>file.ext <<EOT
> #!/bin/sh
> echo "$0 START"
> echo "Now doing some code here"
> echo "$0" END
> EOT
# cat file.ext
#!/bin/sh
echo "/bin/bash START"
echo "Now doing some code here"
echo "/bin/bash" END
#
| Code: | cat >>file.ext <<EOT
#!/bin/sh
echo "$0 START"
echo "Now doing some code here"
echo "$0" END
EOT
|
'>' and '>>' works exactly the same as for echo . |
That's interesting. "file.ext" keeps writing to itself every time you run it.
|
|
Back to top
|
|
 |
recobayu

Joined: 15 Sep 2010 Posts: 87 Location: indonesia
|
Posted: Fri 09 Dec 2011, 19:26 Post subject:
script to repackage after download with ppm |
|
hi everyone,
i'm sorry where to put my question, i hope in this thread is ok.
i finished download aqualung with ppm, and it was installed on my laptop.
now, i look at /root/.package/aqualung-0.9b11-Lucid.files there are many rows representating the file i download.
it's like this:
| Quote: |
/usr/
/usr/local/
/usr/local/lib/
/usr/local/lib/X11/
/usr/local/lib/X11/mini-icons/
/usr/local/lib/X11/mini-icons/aqualung.png
/usr/lib/
/usr/lib/libmpcdec.so.3.1.1
/usr/lib/libmpcdec.so.3
...
|
actually, i can put them one by one. but if there are some script, it can be more fast and interesting.
how to repackage again in a pet or a folder with a script? so i don't need download that aqualung again.
thanks
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Fri 09 Dec 2011, 19:48 Post subject:
Re: script to repackage after download with ppm |
|
| recobayu wrote: | hi everyone,
i'm sorry where to put my question, i hope in this thread is ok.
i finished download aqualung with ppm, and it was installed on my laptop.
now, i look at /root/.package/aqualung-0.9b11-Lucid.files there are many rows representating the file i download.
it's like this:
| Quote: |
/usr/
/usr/local/
/usr/local/lib/
/usr/local/lib/X11/
/usr/local/lib/X11/mini-icons/
/usr/local/lib/X11/mini-icons/aqualung.png
/usr/lib/
/usr/lib/libmpcdec.so.3.1.1
/usr/lib/libmpcdec.so.3
...
|
actually, i can put them one by one. but if there are some script, it can be more fast and interesting.
how to repackage again in a pet or a folder with a script? so i don't need download that aqualung again.
thanks |
mkdir /tmp/aqualung
cd /tmp/aqualung
cp -p /usr/local/lib/X11/mini-icons/aqualung.png .
cp -p /usr/lib/libmpcdec.so.3* .
...
Last edited by jpeps on Fri 09 Dec 2011, 20:23; edited 1 time in total
|
|
Back to top
|
|
 |
puppyluvr

Joined: 06 Jan 2008 Posts: 3053 Location: Chickasha Oklahoma
|
Posted: Fri 09 Dec 2011, 20:05 Post subject:
|
|
Hello,
I dont believe that is a complete list, as the binaries etc are not listed..
Add them all before making a pet..
Anyone want to help with a script to read the final /* lines in any /root/.packages file, then copy the actual files to a dir...
RePet-1.0
I cant remember how to get cat to ignore things...
_________________ "Close the "Windows", and open your eyes, to a whole new world"
http://puppylinuxstuff.meownplanet.net/puppyluvr/
http://theplpd.webs.com/
Nothing but Puppy since 2.15CE...
|
|
Back to top
|
|
 |
jpeps
Joined: 31 May 2008 Posts: 2449
|
Posted: Fri 09 Dec 2011, 20:48 Post subject:
|
|
More sophisticated: Usage newpet [name]
Makes [name].pet in /tmp
| Code: |
#!/bin/sh
if [ ! -f /root/.packages/${1}.files ]; then
echo "package doesn't exist"
exit
fi
[ -f /tmp/list ] && rm /tmp/list
[ -d /tmp/"$1" ] && rm -r /tmp/"$1"
mkdir /tmp/"$1"
for i in `cat /root/.packages/${1}.files`; do
echo "$i" >> /tmp/list
done
while read line; do
if [ -f $line ]; then
DIR="$(dirname ${line})"
[ -d /tmp/${1}/${DIR} ] || mkdir -p /tmp/${1}/${DIR}
cp -p "$line" /tmp/${1}/${DIR}
fi
done </tmp/list
cd /tmp
dir2pet "$1"
|
Last edited by jpeps on Fri 09 Dec 2011, 21:10; edited 3 times in total
|
|
Back to top
|
|
 |
RSH

Joined: 05 Sep 2011 Posts: 1564 Location: Germany
|
Posted: Fri 09 Dec 2011, 20:54 Post subject:
|
|
| jpeps wrote: | | That's interesting. "file.ext" keeps writing to itself every time you run it. |
Does it mean, this could be used to create a log file or is it an unwanted 'loop'?
RSH
_________________ Useful Software for Puppy!
LazY Puppy - a Paradise Puppy! - DE & EN ISO 2.0.2-0.0.5 available
|
|
Back to top
|
|
 |
recobayu

Joined: 15 Sep 2010 Posts: 87 Location: indonesia
|
Posted: Fri 09 Dec 2011, 21:15 Post subject:
|
|
thanks jpep, now i have aqualung.pet
i like coding, it makes fast. step by step i learn bash programming from this forum.
|
|
Back to top
|
|
 |
sunburnt

Joined: 08 Jun 2005 Posts: 4016 Location: Arizona, U.S.A.
|
Posted: Fri 09 Dec 2011, 21:47 Post subject:
|
|
Or you can gather all the lines ( the whole file ) into a variable.
| Code: | | echo "(Text)" > (File) |
This writes the entire multi. lined file in one shot.
The double quotes " " are needed to preserve the line-feeds.
|
|
Back to top
|
|
 |
Karl Godt

Joined: 20 Jun 2010 Posts: 2733 Location: Kiel,Germany
|
Posted: Fri 09 Dec 2011, 22:32 Post subject:
|
|
| RSH wrote: | | jpeps wrote: | | That's interesting. "file.ext" keeps writing to itself every time you run it. |
Does it mean, this could be used to create a log file or is it an unwanted 'loop'?
RSH |
I always copy the code into the console first .
This was not intended to create any loops at all , but i will play around with it
To create a log file it is pssible to use the
| Code: | | logsave -a logfile.log COMMAND |
command
OR
| Code: | | echo 'DBG : what i wanna say here' >> logfile.log |
OR
| Code: | cat>logtest.sh <<EndOfText
exec 1>>logfile.log 2>>error.log
echo 'DBG : what i wanna say here'
EndOfText
source logtest.sh &
sleep 1
cat logfile.log
cat error.log |
which is the simpliest solution as far as i can tell (look into /etc/rc.d/rc.sysinit for an example [ "$LOGLEVEL" ] || exec 1>/tmp/bootsysinit.log 2>&1 ) .
|
|
Back to top
|
|
 |
PANZERKOPF
Joined: 16 Dec 2009 Posts: 251 Location: Earth
|
Posted: Sat 10 Dec 2011, 13:26 Post subject:
Re: Question about Shell Script (#!/bin/sh) |
|
| RSH wrote: | I want to know how can i write multiple lines into a text file via "echo" (or is there another command existing)?
|
Yet another solution:
echo -e "line1\nline2\nline3\nlineN"
_________________ SUUM CUIQUE.
|
|
Back to top
|
|
 |
|