I'd say that n1 could be the problem. I reckon -n 1 might work.Bruce B wrote:I think something didn't do right, so I decided to echo -nCode: Select all
read n1 a -p "Enter choice "
Basic Shell (Console) operation for beginners
Shep,As a technique to be applied to other puppies, this will only work if you can
be sure the contents of file PUPSTATE will adhere to identical syntax for all
puplets. Can you be sure of this? Otherwise, a more robust algorithm will be
needed
After about seven years working with Puppy, I can be confident in saying,
'Barry changes things.' I'm certain I don't know what he will do in the future.
In this case, I might, (probably will), force an exit, with a printed comment,
for all versions I haven't personally tested.
It would also be a good exercise for this audience to test and rework existing
code, as needed.
Thanks,
Bruce
~
Boot sector backups
Sometimes we have data damaging problems. I'd like the reader to read the
linked article below, from our regular users section.
Download the script and run it.
If anything ever happens to a boot sector, especially a Microsoft boot sector,
you can be good to go in a matter of a few minutes. Boot sectors can be
damaged by the operator, malware and maybe even some shareware trying to
make sure you don't reinstall.
Can't mount NTFS partition in Puppy 5.1
~
Sometimes we have data damaging problems. I'd like the reader to read the
linked article below, from our regular users section.
Download the script and run it.
If anything ever happens to a boot sector, especially a Microsoft boot sector,
you can be good to go in a matter of a few minutes. Boot sectors can be
damaged by the operator, malware and maybe even some shareware trying to
make sure you don't reinstall.
Can't mount NTFS partition in Puppy 5.1
~
Bruce B wrote:After about seven years working with Puppy, I can be confident in saying,
'Barry changes things.' I'm certain I don't know what he will do in the future.
I have further polished the code I suggested for setting pupdir & pupfile a few posts back. Scroll back to see. It's now down to one line, so I probably can't reduce it much further.It would also be a good exercise for this audience to test and rework existing code, as needed.
Still pondering a one-line method for incrementing the suffix on a filename, to increment from file_a to file_b. Will post if/when I solve it.
Numbering Lines
I decided to try posting scripts with line numbers for easy reference.
It is entirely feasible the reader will not understand some aspects of
of a script I post. By referencing line numbers I can explain easily,
things I think should be explained.
-) This is a script to number lines.
4) The variables don't know about the command line parameters.
$@ is how I pass the parameters to variables. Commonly you will see
"$@" as the way to do it. In this case, I'm only passing a filename. All
my file names follow Linux conventions, so there is no need to quote.
4-8) Are function calls from main. Somewhat like a goto command, but
goto is not necessary. The name of the function tells Bash to go to that
function and execute the commands within the function, then return to main
and execute the next line if there is one.
15-16) I exit with a error code of 1, if the tests are true.
22) grep can count lines by using the -c switch. What all lines have in
common is a beginning of the line. The ^ says to grep the beginning of
the line. This combination makes counting lines easy. The variable will be
used later in the script.
26) function get_format. I want to format my lines right justified.
I set a variable to help me do that, when later, I use the printf command.
By formatting the line numbering this way, it makes the numbered file
easier to read.
41) Will make a numbered file to be used later.
46) The printf command prints formatted and does many other things. Printf
probably means 'print formatted'
53) Introducing the external 'paste' command. It pastes two files side by
side, making the output joined columns. You can study the command in the
script. It uses the most basic command of paste.
58) Strips the path from my script and sets a variable called script,
which contains only the name of the script. I don't know how to pass $0 to
a function, so I did it outside a function. The variable called 'script'
can be used inside any function.
59) Main is the command to go to the function main and start executing the
commands inside the function.
The program flow in Bash is: execute from top to bottom. The same flow
exists when we use functions. But we can give the appearance of a
different flow with functions. And even gain flow control. But the execution
Bash uses is still top to bottom.
A function is not a command, Bash reads the file from top to bottom and
doesn't do anything until it runs into a command. The command 'main' tells
Bash to go to the function main. Main calls functions. When the last line in a
function is complete, Bash returns to execute the next command from where
the function was called.
Main has the command 'exit'. When we use the command exit anywhere, Bash
does just that. This means that if there were a command after the main
command, it would be of null effect, because the function main exited the
script after its commands were finished.
~
I decided to try posting scripts with line numbers for easy reference.
It is entirely feasible the reader will not understand some aspects of
of a script I post. By referencing line numbers I can explain easily,
things I think should be explained.
-) This is a script to number lines.
4) The variables don't know about the command line parameters.
$@ is how I pass the parameters to variables. Commonly you will see
"$@" as the way to do it. In this case, I'm only passing a filename. All
my file names follow Linux conventions, so there is no need to quote.
4-8) Are function calls from main. Somewhat like a goto command, but
goto is not necessary. The name of the function tells Bash to go to that
function and execute the commands within the function, then return to main
and execute the next line if there is one.
15-16) I exit with a error code of 1, if the tests are true.
22) grep can count lines by using the -c switch. What all lines have in
common is a beginning of the line. The ^ says to grep the beginning of
the line. This combination makes counting lines easy. The variable will be
used later in the script.
26) function get_format. I want to format my lines right justified.
I set a variable to help me do that, when later, I use the printf command.
By formatting the line numbering this way, it makes the numbered file
easier to read.
41) Will make a numbered file to be used later.
46) The printf command prints formatted and does many other things. Printf
probably means 'print formatted'
53) Introducing the external 'paste' command. It pastes two files side by
side, making the output joined columns. You can study the command in the
script. It uses the most basic command of paste.
58) Strips the path from my script and sets a variable called script,
which contains only the name of the script. I don't know how to pass $0 to
a function, so I did it outside a function. The variable called 'script'
can be used inside any function.
59) Main is the command to go to the function main and start executing the
commands inside the function.
The program flow in Bash is: execute from top to bottom. The same flow
exists when we use functions. But we can give the appearance of a
different flow with functions. And even gain flow control. But the execution
Bash uses is still top to bottom.
A function is not a command, Bash reads the file from top to bottom and
doesn't do anything until it runs into a command. The command 'main' tells
Bash to go to the function main. Main calls functions. When the last line in a
function is complete, Bash returns to execute the next command from where
the function was called.
Main has the command 'exit'. When we use the command exit anywhere, Bash
does just that. This means that if there were a command after the main
command, it would be of null effect, because the function main exited the
script after its commands were finished.
Code: Select all
0 #!/bin/bash
1
2 main() {
3
4 sanity $@
5 count_infile_lines $@
6 get_format $@
7 make_numbers
8 paste_files $@
9 exit 0
10
11 }
12
13 sanity() {
14
15 [ ! $1 ] && echo "Enter filename to number" && exit 1
16 [ ! -f $1 ] && echo "File $2 doesn't exist" && exit 1
17
18 }
19
20 count_infile_lines() {
21
22 lines=`grep -c ^ $1`
23
24 }
25
26 get_format() {
27
28 if [ "$lines" -le "9" ] ; then
29 format=1
30 elif [ "$lines" -le "99" ] ; then
31 format=2
32 elif [ "$lines" -le "999" ] ; then
33 format=3
34 else
35 echo "Error, exiting"
36 exit 1
37 fi
38
39 }
40
41 make_numbers() {
42
43 [ -f /tmp/${script}.tmp ] && rm /tmp/${script}.tmp
44
45 for ((i;i<=${lines};i++)) ; do
46 printf "%${format}d \n" $i >> /tmp/${script}.tmp
47 done
48
49 }
50
51 paste_files() {
52
53 paste /tmp/${script}.tmp $1 > $1.nbr
54 echo "Numbered file saved as \"$1.nbr\""
55
56 }
57
58 script=`basename $0`
59 main $@
60
Nesting Functions
My primary purpose in this post is to let you know you can nest
functions it. Also, explain a little more about functions.
You could also do like this
The difference shows up in how either is used.
Defined as a function, we simply say mag or cya
Defined as a variable, we have to add the $ to use it as shown here:
$mag or $cya
The concept of the function I wish to share is: Bash reads the script
from top to bottom. Each time it encounters a command, it executes
the command. When finished, with the command, it executes the
next command down the list.
Functions are not commands. Although they contain commands.
What we are effectively doing is making programs or routines,
however you wish to call them. These are available, after read by
Bash. They exist in RAM. Bash will use them as commands, anytime
we say the name of our function.
After the script closes, all our little programs disappear.
~
My primary purpose in this post is to let you know you can nest
functions it. Also, explain a little more about functions.
Code: Select all
make_colors() {
mag() {
echo -en "\033[35;1m"
}
cya() {
echo -en "\033[36;1m"
}
}
Code: Select all
mag=`echo -en "\033[35;1m"`
cya=`echo -en "\033[36;1m"`
Defined as a function, we simply say mag or cya
Defined as a variable, we have to add the $ to use it as shown here:
$mag or $cya
The concept of the function I wish to share is: Bash reads the script
from top to bottom. Each time it encounters a command, it executes
the command. When finished, with the command, it executes the
next command down the list.
Functions are not commands. Although they contain commands.
What we are effectively doing is making programs or routines,
however you wish to call them. These are available, after read by
Bash. They exist in RAM. Bash will use them as commands, anytime
we say the name of our function.
After the script closes, all our little programs disappear.
~
Save this session (y,n) ?
When running Puppy on a Flash Stick, it saves the session when
rebooting. Often, I didn't make any changes during the session I want
to keep. Sometimes, there might be changes I don't want to keep.
In this post, I show how the user can decide if he wants to save the
session.
My $PUPMODE is 13. The version is Lupu 5.20. The code I want to
modify, I find in /etc/rc.d/rc.shutdown beginning at line 849.
Here is the original code
Here is the modified code : see lines 3-10, original lines 3 & 4 are now
at lines 7 & 8
~
When running Puppy on a Flash Stick, it saves the session when
rebooting. Often, I didn't make any changes during the session I want
to keep. Sometimes, there might be changes I don't want to keep.
In this post, I show how the user can decide if he wants to save the
session.
My $PUPMODE is 13. The version is Lupu 5.20. The code I want to
modify, I find in /etc/rc.d/rc.shutdown beginning at line 849.
Here is the original code
Code: Select all
0 13) #PDEV1 and PUPSFS and PUPSAVE
1 #/initrd/pup_rw has tmpfs, pup_ro1 has ${DISTRO_FILE_PREFIX}save.2fs file {cut out}
2 #the above are in unionfs at /.
3 echo "Saving session to $SAVEFILE (${SAVEPART})..." >/dev/console
4 /usr/sbin/snapmergepuppy /initrd/pup_ro1 /initrd/pup_rw
5 ;;
at lines 7 & 8
Code: Select all
0 13) #PDEV1 and PUPSFS and PUPSAVE
1 #/initrd/pup_rw has tmpfs, pup_ro1 has ${DISTRO_FILE_PREFIX}save.2fs {cut out}
2 #the above are in unionfs at /.
3 echo -n "Save this session (y,n) ? " >/dev/console
4 read ans
5 if [ "$ans" = "y" ] ; then
6
7 echo "Saving session to $SAVEFILE (${SAVEPART})..." >/dev/console
8 /usr/sbin/snapmergepuppy /initrd/pup_ro1 /initrd/pup_rw
9
10 fi
11 ;;
Customizing Your Terminal Emulator Defaults
First a little note on stderr and stdout
urxvt --help > urxvt.txt (doesn't work)
urxvt --help 2> urxvt.txt (works)
The reason why the first example fails is because urxvt --help prints to
stderr and not stdout
The first example is to redirect stdout to a file. After discovering
urxvt --help doesn't print to stdout, I changed the command.
Add the 2> and you're redirecting stderr.
If you haven't ran into this previously, you will in the future.
Rxvt and urxvt have a lot of options you can use to change looks and
behavior. Below are the options I applied. You will probably want other
options. Open the file ~/.Xresources and modify it according to the
formatting style below.
There is a file in Puppy /usr/share/X11/rgb.txt which gives loads of
color information, very helpful, if you want to apply colors by name.
Here is, what I think is the entire list of urxvt options.
~
First a little note on stderr and stdout
urxvt --help > urxvt.txt (doesn't work)
urxvt --help 2> urxvt.txt (works)
The reason why the first example fails is because urxvt --help prints to
stderr and not stdout
The first example is to redirect stdout to a file. After discovering
urxvt --help doesn't print to stdout, I changed the command.
Add the 2> and you're redirecting stderr.
If you haven't ran into this previously, you will in the future.
Rxvt and urxvt have a lot of options you can use to change looks and
behavior. Below are the options I applied. You will probably want other
options. Open the file ~/.Xresources and modify it according to the
formatting style below.
There is a file in Puppy /usr/share/X11/rgb.txt which gives loads of
color information, very helpful, if you want to apply colors by name.
Code: Select all
urxvt*title:Bash
urxvt*geometry:80x25+224+345
urxvt*pointerBlankDelay:5
urxvt*iconName:urxvt
urxvt*externalBorder:2
urxvt*font:7x14B
urxvt*background:black
urxvt*foreground:white
urxvt*scrollWithBuffer:true
urxvt*pastableTabs:false
urxvt*saveLines:9000
urxvt*scrollBar:false
urxvt*cursorColor:grey50
rxvt*title:Bash
rxvt*geometry:80x25+224+345
rxvt*pointerBlankDelay:5
rxvt*iconName:rxvt
rxvt*externalBorder:2
rxvt*font:7x14B
rxvt*background:black
rxvt*foreground:white
rxvt*scrollWithBuffer:true
rxvt*pastableTabs:false
rxvt*saveLines:9000
rxvt*scrollBar:false
rxvt*cursorColor:grey50
Code: Select all
termName: string
geometry: geometry
chdir: string
reverseVideo: boolean
loginShell: boolean
jumpScroll: boolean
skipScroll: boolean
pastableTabs: boolean
scrollstyle: mode
scrollBar: boolean
scrollBar_right: boolean
scrollBar_floating: boolean
scrollBar_align: mode
thickness: number
scrollTtyOutput: boolean
scrollTtyKeypress: boolean
scrollWithBuffer: boolean
inheritPixmap: boolean
transparent: boolean
tintColor: color
shading: number
utmpInhibit: boolean
urgentOnBell: boolean
visualBell: boolean
mapAlert: boolean
meta8: boolean
mouseWheelScrollPage: boolean
tripleclickwords: boolean
insecure: boolean
cursorUnderline: boolean
cursorBlink: boolean
pointerBlank: boolean
background: color
foreground: color
color0: color
color1: color
color2: color
color3: color
color4: color
color5: color
color6: color
color7: color
color8: color
color9: color
color10: color
color11: color
color12: color
color13: color
color14: color
color15: color
colorBD: color
colorIT: color
colorUL: color
colorRV: color
underlineColor: color
scrollColor: color
troughColor: color
highlightColor: color
cursorColor: color
cursorColor2: color
pointerColor: color
pointerColor2: color
borderColor: color
font: fontname
boldFont: fontname
italicFont: fontname
boldItalicFont: fontname
intensityStyles: boolean
inputMethod: name
preeditType: style
imLocale: string
imFont: fontname
title: string
iconName: string
saveLines: number
depth: number
buffered: boolean
transient-for: windowid
override-redirect: boolean
hold: boolean
externalBorder: number
internalBorder: number
borderLess: boolean
lineSpace: number
skipBuiltinGlyphs: boolean
pointerBlankDelay: number
backspacekey: string
deletekey: string
print-pipe: string
modifier: modifier
cutchars: string
answerbackString: string
secondaryScreen: boolean
secondaryScroll: boolean
keysym.sym: keysym
Exit Codes - && ||
Your program returns an exit code. You don't see it on screen, but Bash
sees it. An exit code of 0 is how Bash interprets a successful execution.
Or if you prefer: a true condition.
In our programming we can measure and/or see the exit code with $?
Lately, I've been using 'exit 1' or 'exit 0' in some of my script examples.
What I'm trying to do is set a good example.
If you don't specify an exit code, your script will, (in all probability)
return the 0 on its own, after successful execution.
You can test it like this: scriptname && echo $?
The && will only run the next command if Bash calculates the script
ran successfully.
Say for example, our command structure is: Do A and B and C.
The logic is: But only do B if A was successful. And only do C if B was
successful.
(Off subject for a moment. You do know about using the up arrow key
to get your last command back, I hope. Otherwise you have been
typing too much.)
Here are some exercises to work on, if you want to, until you get the
grasp of using exit codes and the && or || instructions.
I will presume /dev/sda1 is mounted
cat /proc/mounts | grep /dev/sda1 > /dev/null && echo $?
You should see a 0 on screen. That is the exit code of the last
command in the string, which would be grep's exit code.
Now change to sda11 which I presume isn't mounted
cat /proc/mounts | grep /dev/sda11 > /dev/null && echo $?
You shouldn't see anything on screen. The && didn't allow the
following command to run, because grep didn't return a true find.
Now change the && to ||
cat /proc/mounts | grep /dev/sda11 > /dev/null || echo $?
You should see a 1 on the screen, that is grep's exit code for no
successful find match.
The && will allow execution on a true condition and the || allows
execution on false or OR condition, which is what the || means.
echo yes | grep yes >/dev/null && echo yes || echo not yes
Then change the first yes to something else, you will see exactly how
it works.
Summary: By using exit codes properly, we can sometimes control
execution flow without the need for if statements and tests. The exit
code in these cases is the test, the answer we need.
~
Your program returns an exit code. You don't see it on screen, but Bash
sees it. An exit code of 0 is how Bash interprets a successful execution.
Or if you prefer: a true condition.
In our programming we can measure and/or see the exit code with $?
Lately, I've been using 'exit 1' or 'exit 0' in some of my script examples.
What I'm trying to do is set a good example.
If you don't specify an exit code, your script will, (in all probability)
return the 0 on its own, after successful execution.
You can test it like this: scriptname && echo $?
The && will only run the next command if Bash calculates the script
ran successfully.
Say for example, our command structure is: Do A and B and C.
The logic is: But only do B if A was successful. And only do C if B was
successful.
(Off subject for a moment. You do know about using the up arrow key
to get your last command back, I hope. Otherwise you have been
typing too much.)
Here are some exercises to work on, if you want to, until you get the
grasp of using exit codes and the && or || instructions.
I will presume /dev/sda1 is mounted
cat /proc/mounts | grep /dev/sda1 > /dev/null && echo $?
You should see a 0 on screen. That is the exit code of the last
command in the string, which would be grep's exit code.
Now change to sda11 which I presume isn't mounted
cat /proc/mounts | grep /dev/sda11 > /dev/null && echo $?
You shouldn't see anything on screen. The && didn't allow the
following command to run, because grep didn't return a true find.
Now change the && to ||
cat /proc/mounts | grep /dev/sda11 > /dev/null || echo $?
You should see a 1 on the screen, that is grep's exit code for no
successful find match.
The && will allow execution on a true condition and the || allows
execution on false or OR condition, which is what the || means.
echo yes | grep yes >/dev/null && echo yes || echo not yes
Then change the first yes to something else, you will see exactly how
it works.
Summary: By using exit codes properly, we can sometimes control
execution flow without the need for if statements and tests. The exit
code in these cases is the test, the answer we need.
~
An easier way
If you have been playing around with the different effects you
can make on Urxvt from this post, you have noticed you need
to restart X, after making your changes, for the new settings to take
effect.
Here is a shortcut you can use in order to see the results without
restarting X.
~
If you have been playing around with the different effects you
can make on Urxvt from this post, you have noticed you need
to restart X, after making your changes, for the new settings to take
effect.
Here is a shortcut you can use in order to see the results without
restarting X.
Code: Select all
#!/bin/bash
xrdb -merge -nocpp /root/.Xresources
Urxvt Title Tools
cdir sets your urxvt title to the current working directory
utitle set your own title, if you have spaces in the title, quote the input
File attached: urxvt-title-tools.zip
Note: I didn't figure how to do this - I learned it.
~
cdir sets your urxvt title to the current working directory
Code: Select all
#!/bin/bash
printf '\33]2;%s\007' `pwd`
utitle set your own title, if you have spaces in the title, quote the input
Code: Select all
#!/bin/bash
printf '\33]2;%s\007' "$1"
File attached: urxvt-title-tools.zip
Code: Select all
Archive: urxvt-title-tools.zip
Length Date Time Name
--------- ---------- ----- ----
40 2011-05-06 03:14 utitle
41 2011-05-06 18:35 cdir
--------- -------
81 2 files
~
- Attachments
-
- urxvt-title-tools.zip
- (379 Bytes) Downloaded 327 times
Comment A Help File
Some executable files have lots of options and combinations of
options. Even pages full of options.
I like an easy way to build a script and have all the options available
to me in the script.
In the example, below I show how build a script for mp3blaster, having
all options available as you build the script. I choose mp3blaster for
brevity.
The tool I made to make the comments is called commentp.
It is trivial enough you probably want to just type in the command,
rather than have a file to pipe the command.
~
Some executable files have lots of options and combinations of
options. Even pages full of options.
I like an easy way to build a script and have all the options available
to me in the script.
In the example, below I show how build a script for mp3blaster, having
all options available as you build the script. I choose mp3blaster for
brevity.
Code: Select all
#/bin/bash
mp3blaster --option --option --option --option *.mp3
# Mp3blaster v3.2.4 (C)1997 - 2009 Bram Avontuur.
# Usage:
# mp3blaster [options]
# mp3blaster [options] [file1 ...]
# Play one or more mp3's
# mp3blaster [options] --list/-l <playlist.lst>
# Load a playlist but don't start playing.
# mp3blaster [options] --autolist/-a <playlist.lst>
# Load a playlist and start playing.
#
# Options:
# --downsample/-2: Downsample (44->22Khz etc)
# --8bits/-8: 8bit audio (autodetected)
# --config-file/-c=file: Use other config file than the default
# ~/.mp3blasterrc
# --debug/-d: Log debug-info in $HOME/.mp3blaster.
# --status-file/-f=file: Keep info on the mp3s being played, in the
# specified file.
# --help/-h: This help screen.
# --mixer-device/-m: Mixer device to use (use 'NAS' for NAS mixer)
# --no-mixer/-n: Don't start the built-in mixer.
# --chroot/-o=<rootdir>: Set <rootdir> as mp3blaster's root dir.
# This affects *ALL* file operations in mp3blaster!!(including
# playlist reading&writing!) Note that only users with uid 0
# can use this option (yet?). This feature will change soon.
# --playmode/-p={onegroup,allgroups,allrandom}
# Default playing mode is resp. Play first group only, Play
# all groups, Play all songs in random order.
# --dont-quit/-q: Don't quit after playing mp3[s] (only makes sense
# in combination with --autolist or files from command-line)
# --repeat/-R: Repeat playlist.
# --runframes/-r=<number>: Number of frames to decode in one loop.
# Range: 1 to 10 (default=5). A low value means that the
# interface (while playing) reacts faster but slow CPU's might
# hick. A higher number implies a slow interface but less
# hicks on slow CPU's.
# --sound-device/-s=<device>: Device to use to output sound.
# Default for your system is /dev/dsp.
# If you want to use NAS (Network Audio System) as playback
# device, then enter the nasserver's address as device (e.g.
# host.name.com:0; it *must* contain a colon)
# --threads/-t=<amount>: Numbers of threads to use for buffering
# (only works if mp3blaster was compiled with threads). Range is
# 0..500 in increments of 50 only.
# --version,v: Display version number.
Code: Select all
sed 's/^/# /'
rather than have a file to pipe the command.
~
Find files in big repositories ( easily )
I have used Debian and Slackware packages quite successfully,
with Puppy over a long period of time. Generally, I use Debian files,
because I find what I want there and they work.
I install them as .deb packages, both directly and manually using
Midnight Commander.
This post is a how-to. How you can find files on these big
repositories, without actually going there and peruse directories.
Here is How-To
1) Make directory /var/repo
2) Download the files below
Slackware file at top level of ftp slackware directory
ls-lR.gz - about 1.3MB
Debian same file at top level of ftp debian directory
ls-lR.gz - about 6.9 MB - (55 MB uncompressed, but we
don't decompress it)
Save as
/var/repos/slackware-ls-lR.gz
and
/var/repos/debian-ls-lR.gz
3) Download and unzip the attached script to your path
~~~~~~~~~~~~~~~~~~~
Script Comments
-) We use and carry to functions the quoted $@, the reason is when
using grep we might really need to send quoted input to the program.
BTW, many programmers always do it this way. It is a good practice.
I have reasons of my own not to quote, in many cases, but that is
off topic.
37) We use zcat to search inside the gzipped archive. You don't
want to uncompress it, because its a big waste of space.
39) Introducing "-s" for use in conditional tests. The test is true
if the file exists and is not empty. An empty files means our search
didn't give results.
43) In the read command you see the "n 1", this says act on one key
press. It helps with laziness, because you don't have to hit the enter
key.
-) I'm only attaching the script for the Debian file. For practice,
take the same script and convert it to work with the Slackware archive.
finddeb
Attached file finddeb.zip
~
I have used Debian and Slackware packages quite successfully,
with Puppy over a long period of time. Generally, I use Debian files,
because I find what I want there and they work.
I install them as .deb packages, both directly and manually using
Midnight Commander.
This post is a how-to. How you can find files on these big
repositories, without actually going there and peruse directories.
Here is How-To
1) Make directory /var/repo
2) Download the files below
Slackware file at top level of ftp slackware directory
ls-lR.gz - about 1.3MB
Debian same file at top level of ftp debian directory
ls-lR.gz - about 6.9 MB - (55 MB uncompressed, but we
don't decompress it)
Save as
/var/repos/slackware-ls-lR.gz
and
/var/repos/debian-ls-lR.gz
3) Download and unzip the attached script to your path
~~~~~~~~~~~~~~~~~~~
Script Comments
-) We use and carry to functions the quoted $@, the reason is when
using grep we might really need to send quoted input to the program.
BTW, many programmers always do it this way. It is a good practice.
I have reasons of my own not to quote, in many cases, but that is
off topic.
37) We use zcat to search inside the gzipped archive. You don't
want to uncompress it, because its a big waste of space.
39) Introducing "-s" for use in conditional tests. The test is true
if the file exists and is not empty. An empty files means our search
didn't give results.
43) In the read command you see the "n 1", this says act on one key
press. It helps with laziness, because you don't have to hit the enter
key.
-) I'm only attaching the script for the Debian file. For practice,
take the same script and convert it to work with the Slackware archive.
finddeb
Code: Select all
0 #!/bin/bash
1
2 main() {
3
4 variables
5 sanity "$@"
6 searchfile "$@"
7 exit 0
8
9 }
10
11 variables() {
12
13 directory=/var/repos
14 file=debian-ls-lR.gz
15 tmpdir=/tmp
16 tmpfile=debian.txt
17
18 }
19
20 sanity() {
21
22 [ ! -f $directory/$file ] \
23 && echo -n "Required file: " \
24 && echo -n "$directory/$file doesn't" \
25 && echo " exist, exiting . . ." && exit
26
27 if [ ! $1 ] ; then
28 echo -n "You need to enter a search criteria"
29 echo " for archive \"$file\""
30 fi
31
32 }
33
34 searchfile() {
35
36 [ -f $tmpdir/$tmpfile ] && rm $tmpdir/$tmpfile
37 <$directory/$file zcat | grep -i "$@" > $tmpdir/$tmpfile
38
39 if [ -s $tmpdir/$tmpfile ] ; then
40
41 cat $tmpdir/$tmpfile
42
43 read -p "Save search results (y,n) ? " -n 1 ans
44
45 # note moving to other function depending on answer
46
47 [ "$ans" = "y" ] && saveresults "$@" || echo
48
49 else
50
51 echo No results for "$@"
52
53 fi
54
55 [ -f $tmpdir/$tmpfile ] && rm $tmpdir/$tmpfile
56
57 }
58
59 saveresults() {
60
61 # called from searchfile
62
63 echo
64
65 read -p "Please enter filename prefix: " name
66
67 mv $tmpdir/$tmpfile $directory/$name-$tmpfile
68
69 echo "Results saved as: $directory/$name-$tmpfile"
70
71 }
72
73 main "$@"
74
~
- Attachments
-
- finddeb.zip
- (668 Bytes) Downloaded 300 times
for i in `ls *.deb`; doesn't work in my lucid puppy 525
for i in `ls *.deb`; do undeb $i; shift; done
doesn't work on my puppy (Yes, I know I'm not in 4.21).
for i in *.deb; do undeb $i; done
works (quotes around "*.deb" seem to be optional).
for i in `ls *.deb`; do echo $i; shift; done
returns "ls zynaddsubfx_2.2.1-2.1_i386.deb" instead of "zynaddsubfx_2.2.1-2.1_i386.deb"
presumably the "ls" is the problem.
You might want to edit the original post, as this is a stumbling block in following your tutorial.
I'll try to provide more feedback as I go through the tutorial.
doesn't work on my puppy (Yes, I know I'm not in 4.21).
for i in *.deb; do undeb $i; done
works (quotes around "*.deb" seem to be optional).
for i in `ls *.deb`; do echo $i; shift; done
returns "ls zynaddsubfx_2.2.1-2.1_i386.deb" instead of "zynaddsubfx_2.2.1-2.1_i386.deb"
presumably the "ls" is the problem.
You might want to edit the original post, as this is a stumbling block in following your tutorial.
I'll try to provide more feedback as I go through the tutorial.
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
Re: for i in `ls *.deb`; doesn't work in my lucid puppy 525
I rarely use ls for file operations anymore, just string manipulation and filetype checks with recursion as necessaryausvirgo wrote:presumably the "ls" is the problem.
here is a modified version of my recursive space replace script for example:
Code: Select all
[ $1 ] && [ -d $1 ] && cd $1
for x in * ; do
y=${x// /_}
[ "$x" != "$y" ] && mv "${x}" "${y}"
[ -d $y ] && $0 $y &
done
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].
The example you posted which I bolded is the way I would do it.ausvirgo wrote:for i in `ls *.deb`; do undeb $i; shift; done
doesn't work on my puppy (Yes, I know I'm not in 4.21).
for i in *.deb; do undeb $i; done
works (quotes around "*.deb" seem to be optional).
1) *.deb does the job and is a conventional way of specifying your
filespecs.
2) "*.deb" is as you noted optional. Except if your .deb packages
have spaces in them and perhaps weird characters. A .deb package
shouldn't have spaces or weird characters. My way is - not to quote.
The reason is I want the script to bomb out to alert me there is a
filename I want to change.
3) About the shift in the first example. The "for loop" does its own
shifting.
It may be.ausvirgo wrote: for i in `ls *.deb`; do echo $i; shift; done
returns "ls zynaddsubfx_2.2.1-2.1_i386.deb" instead of
"zynaddsubfx_2.2.1-2.1_i386.deb"
presumably the "ls" is the problem.
It is not my post to edit. And it isn't my topic. I simply make a lot ofausvirgo wrote:You might want to edit the original post, as this is
a stumbling block in following your tutorial.
I'll try to provide more feedback as I go through the tutorial.
posts. Personally, I appreciate the feedback, regardless of who's post
it is.
~
- Moose On The Loose
- Posts: 965
- Joined: Thu 24 Feb 2011, 14:54
After thinking on it
» The space is the delimiter field for commands
» Debian follows the right rules, so one doesn't need to
take into consideration any spaces
» There is no user input
» The 'for loop' would be able to process the input files,
properly, even if they had spaces. Any potential need
for quotes is not in the *.deb
» If the files did have spaces in them, the output wouldn't
work, unless the $i was quoted.
That's all.
~
Code: Select all
for i in *.deb; do
undeb $i
done
» Debian follows the right rules, so one doesn't need to
take into consideration any spaces
» There is no user input
» The 'for loop' would be able to process the input files,
properly, even if they had spaces. Any potential need
for quotes is not in the *.deb
» If the files did have spaces in them, the output wouldn't
work, unless the $i was quoted.
That's all.
~
I did like the cute substitution example though
Code: Select all
for x in * ; do
y=${x// /_}
- technosaurus
- Posts: 4853
- Joined: Mon 19 May 2008, 01:24
- Location: Blue Springs, MO
- Contact:
for small substitutions it is quick and doesn't require sed or tr, but works in ash and other small posix compliant shells. (the strings can be multiple character too, making it a good little trick to use in init scripts)jpeps wrote:I did like the cute substitution example though
Code: Select all
for x in * ; do y=${x// /_}
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].