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 22 Jul 2014, 05:30
All times are UTC - 4
 Forum index » House Training » Beginners Help ( Start Here)
Basic Shell (Console) operation for beginners
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 18 of 24 [350 Posts]   Goto page: Previous 1, 2, 3, ..., 16, 17, 18, 19, 20, 21, 22, 23, 24 Next
Author Message
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 09 May 2011, 03:04    Post subject:  

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).


The example you posted which I bolded is the way I would do it.

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.

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 may be.

ausvirgo 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.


It is not my post to edit. And it isn't my topic. I simply make a lot of
posts. Personally, I appreciate the feedback, regardless of who's post
it is.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Moose On The Loose


Joined: 24 Feb 2011
Posts: 508

PostPosted: Mon 09 May 2011, 10:08    Post subject:  

Quote:

works (quotes around "*.deb" seem to be optional).


A simple version of the rule:

"this is one string that gets wildcarding *"
'this is one string that doesn't get wildcarding *'
this is ten strings one of which gets wildcarding *
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 09 May 2011, 22:22    Post subject:  

After thinking on it

Code:
for i in *.deb; do
    undeb $i
done


» 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.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
jpeps

Joined: 31 May 2008
Posts: 3220

PostPosted: Mon 09 May 2011, 23:37    Post subject:  

I did like the cute substitution example though Smile

Code:

for x in * ; do
   y=${x// /_}
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4275

PostPosted: Tue 10 May 2011, 06:52    Post subject:  

jpeps wrote:
I did like the cute substitution example though Smile

Code:

for x in * ; do
   y=${x// /_}
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)
_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 16 May 2011, 01:33    Post subject:  

Self Confidence

My dad is a retired computer scientist. He started programming in the
mid fifties. This was before computers as we know them today and
before languages.

I had an excellent opportunity to get training from one of the best.
And he was more than happy to train. His skill with math is so
advanced, he can put me to sleep just talking about.

Seeing what it is like to have a real pro with C was too intimidating to
me. Do to loss of confidence, I didn't peruse programming the way I
originally intended. But with the interest I had in computers, I kept
right on writing programs within my skill level, fixing, building,
modifying and everything imaginable. And of course learning and
gaining experience.

About sed

Sed is not bash. It is a stream editor. A utility found in all our Linux
distros. I never took the time to learn it well. Lately I've been
working more with it. I thank Shep for his help, encouragement and
expertise.

I went back a few pages in this topic to study a line he posted. I
couldn't follow it. Back again to that feeling of losing of confidence.

Here is the line.

Code:
ls *.mp3 | sed "h; s/['"'()]//g; :a; s/[ \.]\(.*\.\)/_\1/; ta; x; G; s/\(.*\)\n/mv "\1" /' | sh


Breaking things into small pieces

While I still can't following the line, I've learned enough to not lose the
confidence.

This is more simple than it looks. Just break it down into small pieces.
So the first part I don't understand is the first letter.

If I want to figure it out, I merely need to find a good sed page and
find out what h; means. The next full command I do understand. If I
want to train myself on it merely copy it to the screen and play with
some combinations. Just keep moving through.

Also people like Shep and myself are happy to explain things in
sufficient detail, the learning curve is easier.

Don't quit, or lose confidence. A big script like the kind Barry writes,
when taken as a whole is too much to digest. In fact you can't see
many of his scripts in one or even 10 pages. Primarily, you need to
break things down into small pieces.

A problem I have working with his scripts is keeping track of what
data various VARIABLES might contain. I can figure it out and add
comments so I don't have to wonder.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 16 May 2011, 01:40    Post subject:  

Bash Internal Commands Help

Whoever wrote the internal help for internal commands,
speaks plain English and explains.

I put all the internal help together into one page. Formatted it stay
within eighty columns and added a table of contents.

And attached the file to this post.

~
bash_internal_cmds.zip
Description 
zip

 Download 
Filename  bash_internal_cmds.zip 
Filesize  13.02 KB 
Downloaded  155 Time(s) 

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 16 May 2011, 13:34    Post subject:  

Dirf

Dirf got its name from back in the DOS days. I combined the dir
command and the find utility to make finding files easier, more
explicit.

The command I'm posting is a part of my lstools. It finds files
according to your command line criteria. Very easy to use.

Code:
#!/bin/bash
if [ $1 ] ; then
   ls -ldF * | awk '!/^d/ {print $8}' | grep -i "$1"
else
   ls -ldF * | awk '!/^d/ {print $8}'
fi


Usage Examples

dirf tool - shows all files containing the string "tool" in them. (case insensitive)

dirf ^f - shows all files beginning with the letter f or F

dirf z$ - shows all files ending with the letter z or Z

The main command string

Code:
ls -ldF * | awk '!/^d/ {print $8}' | grep -i "$1"


Broken down

Code:
ls -ldF *

Shows all files in a long listing format, with the dF added
(ls --help for details)

Code:
awk '!/^d/ {print $8}'


The !/^d/ filters out all entries beginning with d. In the ls -l output,
this is all directories. {print $8} prints only column 8, which is the
same as a short listing.

Code:
grep -i "$1"

Searches the column 8 output for matches. The -i makes
the search 'cAsE insensitive'

Shep gave me the suggestion for an improved awk command. Put
two commands into one. Thanks.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 16 May 2011, 15:14    Post subject:  

Ad (All Directories) (another ls tool)

It shows non-hidden directories. No files or links.
Use it the same as dirf, only this is for directories.

Here is the script.

Code:
#!/bin/bash

x=`echo *`
[ "${#x}" -lt  "2" ] && exit

if [ $1 ] ; then
    ls -ldF * | awk '/^d/ {print $8}' | grep -i "$1"
else
    ls -ldF * | awk '/^d/ {print $8}'
fi


Code:
x=`echo *`
[ "${#x}" -lt  "2" ] && exit

If you navigate to an empty directory, this will suppress an ls
error message.

${#x} is not the contents of x it is the byte size of x

If it is only one byte, the value in x is presumed *

That is what ad uses for an exit branch.

Enjoy!

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 16 May 2011, 15:27    Post subject:  

Ahd (displays hidden directories)

Considering the previous two posts, I don't think this requires
an explanation.

Code:
#!/bin/bash

if [ $1 ] ; then
    ls -aldF .* | awk '/^d/ {print $8}' | grep -i "$1"
else
    ls -aldF .* | awk '/^d/ {print $8}'
fi


~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Mon 16 May 2011, 15:31    Post subject:  

Ahf (displays only hidden files)

All the information for this utility is contained in the three posts above.

I think it will be more fun, if you mix and match from the above code
and make your own.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Tue 17 May 2011, 05:50    Post subject:  

Bruce B wrote:
Code:
x=`echo *`
[ "${#x}" -lt  "2" ] && exit

If you navigate to an empty directory, this will suppress an ls
error message.

${#x} is not the contents of x it is the byte size of x

If it is only one byte, the value in x is presumed *

~


Yeah, but.

But what if the directory has only a one byte directory or filename in
it? You didn't think of that?

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Tue 17 May 2011, 09:27    Post subject:  

Introducing lsnow

Sometimes I want to know what files change or get modified when
I run a configuration tool. (my earlier approach was too
cumbersome)

For this purpose: finding files which have just been modified or
created, I wrote lsnow.

It is a newborn, only a few hours old. If anyone finds a problem with
it or can see how to improve it, please post back. Otherwise, enjoy.

Code:
#/bin/bash

main() {

    variables
    cd $STARTDIR
    find_display
    exit 0

}

variables() {

    STARTDIR=/initrd/pup_rw # USER SETTING

    # if a frugal install we only want to search the
    # pupsave file, the sfs files can not change, it
    # is a "big waste" to search them.

    # your pupsave file may not be at the default
    # variable STARTDIR, if not, change it

    nowd=`date +"%Y-%m-%d"`
    ntime=`date +"%k"`

    # get rid of a leading space
    ntime=`echo $ntime`

    # if < 10 hours we need to pad with
    # a leading zero

    if [ "${#ntime}" -eq "1" ] ; then
        ntime="0$ntime"
    fi


}

find_display() {

    echo -n "Pupsave files changed on this date and hour: "
    echo "$nowd $ntime"
    # search files modified on this date
    # within this hour

    # if you modify script and search hidden files,
    # many excludes, for example:
    # found=`ls -lRa | grep -v Cache | grep \
    # "$nowd $ntime:" | awk '!/^d/ {print $8}'`

    found=`ls -lR | grep "$nowd $ntime:" | awk '!/^d/ {print $8}'`


    for i in $found ; do
        x=`find -name $i`
        ls -l --color $x
    done

}

main


Notes from after first post

Will leave code as first displayed for now and add notes

Duplicate files: if more than one file of same name which matches,
the additional file(s) display. Easy to fix by second grep
of output.

New option: Easy to add option allowing user to enter date or time
and date this way, if you want to see all modified files on a whole
day, for example, no problem.

~

_________________
New! Puppy Linux Links Page

Last edited by Bruce B on Wed 18 May 2011, 07:47; edited 2 times in total
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Tue 17 May 2011, 09:49    Post subject:  

Criteria

I ran alsactrl store for the purpose of saving settings, with the
intention of making the changed file immutable.

Generally, I presume somewhere in /etc, but after running alsactrl store,
the file I thought would change didn't. No files changed.

That's what gave rise to the birth of lsnow. Just were did the
settings get stored?

lsnow reported: /var/lib/alsa/asound.state

At first lsnow was just a command. If it is a command which requires
typing more than a few bytes AND I plan to run it in the future, the
criteria for writing a script is probably met.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4275

PostPosted: Tue 17 May 2011, 15:28    Post subject:  

Bruce B wrote:
Bruce B wrote:
Code:
x=`echo *`
[ "${#x}" -lt  "2" ] && exit

If you navigate to an empty directory, this will suppress an ls
error message.

${#x} is not the contents of x it is the byte size of x

If it is only one byte, the value in x is presumed *

~


Yeah, but.

But what if the directory has only a one byte directory or filename in
it? You didn't think of that?

~

[ $x == "*" ] && exit
(may need a backslash for * ... on my Droid again)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 18 of 24 [350 Posts]   Goto page: Previous 1, 2, 3, ..., 16, 17, 18, 19, 20, 21, 22, 23, 24 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Beginners Help ( Start Here)
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.1176s ][ Queries: 13 (0.0140s) ][ GZIP on ]