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 18 Jun 2013, 01:52
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
bashbox: multicall bash script
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 3 of 3 [34 Posts]   Goto page: Previous 1, 2, 3
Author Message
2lss

Joined: 20 Sep 2009
Posts: 225

PostPosted: Sun 13 Mar 2011, 23:13    Post subject:  

technosaurus wrote:
just save this into a script to test the dir_tree portion
Code:
#!/bin/sh
DIR=$1
[ $2 ] && SPACING=$2 || SPACING="|"
for x in `ls $DIR`; do
[ -d $DIR/$x ] &&  echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING  "
done


Sorry to get off subject, but this would work for me. Only problem is when there is a space in the filename.

'for' splits the input by line, and any file name with a space in it throws it off.

Normally I would use double quotes around a variable to prevent this, but with the for/next loop I am not sure.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Mon 14 Mar 2011, 11:38    Post subject:  

as an alternative you can simply use
Code:
DIR=${1:-`pwd`}
SPACING=${2:-|}
cd $DIR
for x in * ; do
[ -d $DIR/$x ] &&  echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING  "
done
I think it will keep the spaces (not on a *nix box, but I think I may have already done similar in dev)

EDIT ... needed to cd to $DIR for this way to work

I also have an efficient recursive space replace script in the dev version if you are interested, but I don't keep files with spaces around, so not well tested - just 1-2 sub-directories or so. It only requires mv (not sed awk or grep as others do - it uses only the shell's internal substring manipulation - resulting in ~1000% speed improvement)

... right now I don't have a net connection at home so I'm trying to work on a dialog/Xdialog wrapper, so that scripts work independent of X/console (I think goingnuts may have done some work on this already?)

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
2lss

Joined: 20 Sep 2009
Posts: 225

PostPosted: Tue 15 Mar 2011, 02:44    Post subject:  

technosaurus wrote:
as an alternative you can simply use
Code:
DIR=${1:-`pwd`}
SPACING=${2:-|}
cd $DIR
for x in * ; do
[ -d $DIR/$x ] &&  echo "$SPACING\`-{"$x && $0 $DIR/$x "$SPACING  "
done
I think it will keep the spaces (not on a *nix box, but I think I may have already done similar in dev)

EDIT ... needed to cd to $DIR for this way to work


I gave this a try. Unfortunately there is still a problem. When the file or directory is evaluated by [ -d $DIR/$x ] if there is a space the test will throw an error. Quoting $DIR/$x causes the test to always fail. I think cd $DIR needs double quotes as well.

I will give the dev version a shot and see how it works.

EDIT: Which version is the dev version?

technosaurus wrote:

It only requires mv (not sed awk or grep as others do - it uses only the shell's internal substring manipulation - resulting in ~1000% speed improvement)

Thats pretty awesome. I never put much thought into the performance aspect of shell scripting.
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Tue 15 Mar 2011, 10:54    Post subject:  

I'll have to upload a new DEV version, but I need to transfer it to my droid or go find a hotspot somewhere (it may be a day or 2). My wife has our Altel internet stuff with her in Illinois.
_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 3 of 3 [34 Posts]   Goto page: Previous 1, 2, 3
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
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.0590s ][ Queries: 12 (0.0178s) ][ GZIP on ]