The time now is Sat 18 May 2013, 18:12
All times are UTC - 4 |
|
Page 19 of 23 [344 Posts] |
Goto page: Previous 1, 2, 3, ..., 17, 18, 19, 20, 21, 22, 23 Next |
| Author |
Message |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Tue 17 May 2011, 23:53 Post subject:
|
|
| technosaurus wrote: | | [ $x == "*" ] && exit |
It doesn't seem to work. The left part of the comparison might also
need quotes.
In this case, I think I'll do like the pros. Spend 60 bytes writing up a bug
report, rather than 10 bytes to fix the program.
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Wed 18 May 2011, 06:27 Post subject:
|
|
lspet
With this lstool you can view the contents of your pet package.
Helpful especially, if you have to manually 'unpet'.
| Code: | #!/bin/bash
tar -tzf 2>/dev/null "$@" |
lstgz
For previewing your tar.gz and .tgz files
The code is identical to lspet, I wonder why?
| Code: | #!/bin/bash
tar -tzf 2>/dev/null "$@" |
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Shep
Joined: 08 Nov 2008 Posts: 840 Location: GIRT-BY-SEA
|
Posted: Wed 18 May 2011, 10:11 Post subject:
|
|
| Bruce B wrote: | | technosaurus wrote: | | [ $x == "*" ] && exit |
It doesn't seem to work. The left part of the comparison might also
need quotes. |
Are you are testing for x being equal to an asterisk?
| Code: | | # x=*; if [ "$x" = '*' ]; then echo xxx; fi |
Instead of the old single brackets, you can use the much more-versatile double square brackets of bash's extended test function. I think you can get away without quoting the $x here because within [[.......]] there is no word splitting:
| Code: | | x=*; if [[ $x == '*' ]]; then echo xxx; fi |
An alternative: save any positional parameters, then you are free to use the super-efficient set to determine whether your directory is empty:
| Code: | | set -- *; if [[ $1 == '*' ]]; then echo directory is empty; fi |
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Fri 27 May 2011, 20:24 Post subject:
|
|
I wrote a little script which will not work. It will work and produce the output shown in the comments after certain characters have been escaped. The escape character is used to change the meaning of the character sent to the 'for loop' is the \ (backslash). The backslash is used to give a literal meaning to the character rather then how bash uses it.
For example: echo ~ displays /root and echo \~ displays ~
| Code: | #!/bin/bash
for i in ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 \
: ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W \
X Y Z [ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v \
w x y z { | } ~
do
echo -n "$i "
done
echo
# ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9
# : ; < = > b @ A B C D E F G H I J K L M N O P Q R
# S T U V W X Y Z [ ] ^ _ ` a b c d e f g h i j k l
# m n o p q r s t u v w x y z { | } ~ |
The idea here is to self teach exactly how characters are interpreted and which need escaped.
~
| Description |
|

Download |
| Filename |
practice.zip |
| Filesize |
372 Bytes |
| Downloaded |
258 Time(s) |
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Sat 28 May 2011, 05:01 Post subject:
|
|
Bash errors
Bash gives an error "command not found"
Sometimes you run into some though ones. This one about takes the cake.
Cross my heart - I was confident I did everything right. I looked at the code over and over and could not find the reason for the command not found.
I didn't find it with the mp editor. I can't find anything wrong with cat.
My dog didn't eat my homework but I think she messed up my script. It happens when I leave tasty stuff on the table, she sometimes jumps up on the keyboard uses it as a launch pad to the table to steal my food.
Here is the problem: She pressed the space bar to move the text to column 154, then I guess entered these characters ~V~R
I don't know this for a fact, but I confronted her and she didn't deny it.
As stated bash finds them and says command not found.
Cat don't display them. With persistence I debugged it and even wrote my own poor man's cat utility called kitty. Kitty won't display this character string on the screen either.
Echo will.
How many times I thought bash was the culprit only to find it wasn't.
Anyone else had tough times trying to figure why things just will not work right sometimes?
Anyone else started thinking the problem is Bash, because you couldn't find the problem in your source?
~~~~
Change subject
Hoping Shep or another sed expert is still around, I have a question.
I want to reduce lines empty lines more than two to double lines.
The obvious approach is to me
sed -e 's/^$^$^$^$/^$^$/' -e 's/^$^$^$/^$^$/'
It works, but I've learned enough to know that a sed expert knows the best way to do it.
Shep, anyone?
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Shep
Joined: 08 Nov 2008 Posts: 840 Location: GIRT-BY-SEA
|
Posted: Sat 28 May 2011, 07:46 Post subject:
|
|
| Bruce B wrote: | | I want to reduce lines empty lines more than two to double lines. |
See whether this is going to do what you want:
sed '/^\n*$/{N; /^\n$/N; /\n$/D;}'
reading from left to right:
if the pattern space is empty or contains only newlines then do everything inside the curly brackets, viz.,
append the next line of input to the pattern space
if the pattern space contains exactly two empty lines then append to the pattern space the next line of input
if the last line was empty, delete the first part of the pattern space and repeat until a non-blank line is encountered
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Sat 28 May 2011, 23:47 Post subject:
|
|
Introducing the file command
In its most simple form we use this external command to help figure what kind of file we are working with with.
In my example, mplayer.dsl has an unknown extension. The Linux distro Damn Small Linux uses it. I want to know what it is. I use file to look at it and report back.
I say file mplayer.dsl
file says: mplayer.dsl: gzip compressed data, from Unix
To learn more I say: gzip -d mplayer.dsl
gzip says: mplayer.dsl: unknown suffix -- ignored
I then say: mv mplayer.dsl mplayer.dsl.gz
Then I say: gzip -d mplayer.dsl.gz
Gzip decompresses it and leaves me with mplayer.dsl
Then I say: file mplayer.dsl
file then says: mplayer.dsl: POSIX tar archive (GNU)
Now I know it is a tar archive
Then I say: tar xvf mplayer.ds
Sure enough it extracts.
To learn more say file --help, for more details consult the man page.
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Sun 29 May 2011, 15:11 Post subject:
|
|
How to make a RAM Disk - step by step
1) Define RAM Disk size
Edit menu.lst and set the size of the disk on the kernel line
ramdisk_size=192000
This would configure to make a disk size of about 192 MB
The 192000 is 192000k but the k is not entered
2) Format the RAM Disk in the file /etc/rc.d/rc.local
mkfs.ext2 -m 0 /dev/ram6
the -m 0 says not to allocate space for the super user. It gives more space and the super user allocation is not needed.
3) Fstab
tell /etc/fstab about the RAM disk
| Code: | /dev/ram6 /mnt/ram ext2 rw,noatime,noauto,shortname=mixed,errors=continue 0 0
| 4) mount RAM disk
Use ROX-Filer mouse options on /mnt/ram
or use the command line
mount /dev/ram6
or
mount /mnt/ram
You can unmount either on the command line or with ROX-Filer
Comments
You can of course use a different disk size, mount point and ram device.
In Puppy we have three basic places to put apps or commands for automatic run.
/etc/rc.d/rc.local
/etc/profile.local
/root/Startup
Here is a guide of what which to use in a variety of circumstances. Any graphics app needs to be put in /root/Startup
Non graphics apps or instructions you only want to run one time per session, put in /ect/rc.d/rc.local
/etc/profile.local is susceptible to being run more than once, something to consider when placing commands in this file
Many readers knew this already. But for those who didn't, now you know.
It is possible that /etc/profile.local doesn't exist. If not make it as a regular text file. It is not a shell script
I use the RAM disk when I have big files or need to batch process files. These files might get modified, converted, deleted, remodified, decoded or encoded, renamed and whatever. This could make for a lot of disk I/O for files that only live a few minutes. The RAM disk speeds things up and saves any disk wear and tear. I also compile in a RAM disk for the same benefits.
The RAM disk I present in this post is what I call - "A true formatted RAM disk"
There are other kinds of RAM disks which can be set up easier. My reason for the so-called true formatted RAM disk is ffmpeg won't write to the other formats.
Thanks
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Indy'spup
Joined: 11 May 2011 Posts: 50 Location: SoCal
|
Posted: Mon 30 May 2011, 13:06 Post subject:
|
|
Ok I got to ask because this is killing me...
Does the Prefix -- used often with a command/function have any specific meaning in bash? As I understand it after the function has run the -- will disable other options pertaining to that function to run and terminate the command cleanly.
ie: --version, or --help etc. etc.
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Mon 30 May 2011, 13:50 Post subject:
|
|
| Indy'spup wrote: | | ie: --version, or --help etc. etc. |
Bash is a command interpreter. I posted the full Bash help on the internal commands and -- is not listed as an internal command.
By which I conclude only that it is not listed.
Set is an internal command and I've seen Shep post examples of set --. I would think -- is an argument the internal command set uses.
Normally we use the -- like this:
cp --help
grep --help
In this case the --help is an argument (parameter?) to the cp and grep commands.
In other words: --help is simply passed on by bash to the external command as an argument.
Bash will pass a bad argument to the cp command. In this example,
I said cp /?
cp replied
[~] cp /?
cp: missing destination file operand after `/?'
Try `cp --help' for more information.
[~]
Issue -- on the CLI and bash reports
[~] --
bash: --: command not found
[~]
This means by itself -- is neither an internal or external command.
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
Shep
Joined: 08 Nov 2008 Posts: 840 Location: GIRT-BY-SEA
|
Posted: Mon 30 May 2011, 23:39 Post subject:
|
|
| Indy'spup wrote: | | Does the Prefix -- used often with a command/function have any specific meaning in bash? |
Not exactly. To the shell that combination of characters means nothing special.
"--" is an argument which is meaningful to most commands. It signals the end of options on that command line, thereby indicating that what follows is to be treated as something other than an option.
For example, suppose you (either intentionally or accidently) believe you had created a file named with the two characters "-u". You might think that the command "ls -u" will indicate whether or not that particular file exists. But you will be in for a surprise.
The "ls" command can take many optional arguments. One such argument is "-u" which tells it to list filenames along with the last time each was accessed. So your command "ls -u" will list all files in the current directory and show their most recent time of access; and it won't list just the one filename you were hoping to see. (Though somewhere in the long listing you will find that file, if it exists.)
To make it clear to "ls" that you want the "-u" string to be seen as a file name and not interpreted as an argument, you can use "ls -- -u"
Had you not known about the "--" argument, or if you were using an older operating system where "--" was found to not be meaningful to "ls", then you could achieve the same outcome by using "ls ./-u" where "." is a universal abbreviation for your current directory.
HTH
|
|
Back to top
|
|
 |
01micko

Joined: 11 Oct 2008 Posts: 7017 Location: qld
|
Posted: Tue 07 Jun 2011, 04:12 Post subject:
|
|
Hi scripters
I knocked up a script the other day mainly so I could make sure i could list the correct dependencies of a package that I was building. Note the -f argument that checks the ro filesystem. Suggestions for improvement are most welcome.
| Code: | #!/bin/sh
#dependency check script
# '-f' param to check if dep is in ro filesystem (frugal)
Usage(){ #basic usage called by '-h' or no args
echo '
usage: -h : display help and exit
-f <app> : check read only filesystem (frugal types only)
<app> : the app you want to check' && exit 1
}
export -f Usage
#no args?
[ ! $1 ] && Usage
case $1 in
*-h*)
Usage
;;
-f) #arg only works with frugals, errors if not
[ ! -d /initrd/pup_ro2 ] && echo "not a frugal install, failure" && exit 1
APP=`which $2`
ROPATH="/initrd/pup_ro2"
;;
*)
APP=`which $1`
ROPATH=""
;;
esac
#meat and spuds
[ ! $APP ] && echo "no such application exists on your system" && exit 1 #does it exist?
FAIL=`ldd $APP|grep -i -E "not|no"`
[[ $FAIL ]] && echo "ldd error, not a dynamic executable" && exit 1 #it may be a script
LIST=`ldd $APP|sed 's/ /%/g'`
for DEP in $LIST #deps loop
do
BASEDEP=`echo $DEP|cut -d '%' -f1`
PATHDEP=`echo $DEP|cut -d '%' -f3`
FOUND=`find $ROPATH/usr/lib -name $BASEDEP`
[ ! $FOUND ] && FOUND=`find $ROPATH/lib -name $BASEDEP`
[ $FOUND ] && continue
[ ! $FOUND ] && echo $PATHDEP >> /tmp/deplist && echo $BASEDEP >> /tmp/finallist
done
NEWLIST=`cat /tmp/deplist`
for SUBDEP in $NEWLIST #deps of deps loop
do
SUBDEPLIST=`ldd $SUBDEP|cut -d ' ' -f1`
for FOUNDSUBDEP in $SUBDEPLIST
do
BASEFOUNDSUBDEP=`echo $FOUNDSUBDEP|cut -d '%' -f1`
FOUNDSUB=`find $ROPATH/usr/lib -name $BASEFOUNDSUBDEP`
[ ! $FOUNDSUB ] && FOUNDSUB=`find $ROPATH/lib -name $BASEFOUNDSUBDEP`
[ $FOUNDSUB ] && continue
[ ! $FOUNDSUB ] && echo "$BASEFOUNDSUBDEP" >> /tmp/finallist
done
done
cat /tmp/finallist|sort -u #display results
#cleanup temp
rm /tmp/finallist 2>/dev/null
rm /tmp/deplist 2>/dev/null
exit 0
#end
|
It checks (or is supposed to) check deps of deps 1 deep.
| Description |
|

Download |
| Filename |
find_deps.gz |
| Filesize |
809 Bytes |
| Downloaded |
216 Time(s) |
_________________ keep the faith .. 
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10816 Location: The Peoples Republic of California
|
Posted: Wed 08 Jun 2011, 01:40 Post subject:
|
|
01micko
Trivial comment, but potentially frustrating, if one doesn't know.
Sometimes executable files are packed with UPX, when they are, the file is a valid executable file with dependencies, problem is, ldd fails, producing a false negative.
(I think an English teacher would fail me on the sentence above)
You check with the file command and get an accurate output.
Not a criticism or suggestion. Just something to put in your toolkit of ever expanding knowledge, in the event you didn't already know about the behavior.
Bruce
~
_________________ New! Puppy Linux Links Page
|
|
Back to top
|
|
 |
01micko

Joined: 11 Oct 2008 Posts: 7017 Location: qld
|
Posted: Wed 08 Jun 2011, 06:00 Post subject:
|
|
yeah, I did actually know about that Bruce.. from you I think in one of these threads. Just didn't think of it..
I wonder if there is a way to decompress the upx'd binaries and be able to check them with ldd?
_________________ keep the faith .. 
|
|
Back to top
|
|
 |
amigo
Joined: 02 Apr 2007 Posts: 1757
|
Posted: Wed 08 Jun 2011, 12:23 Post subject:
|
|
upx -d decompresses bins, but there is no guarantee that the md5sum of the file will be the same after decompressing and then re-compressing -unless it is done more than once. After doing it once, repeating the operation will not change the md5sum anymore.
|
|
Back to top
|
|
 |
|
|
Page 19 of 23 [344 Posts] |
Goto page: Previous 1, 2, 3, ..., 17, 18, 19, 20, 21, 22, 23 Next |
|
|
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
|