RE: [opensuse] OT: bash F1
- From: "Nick Zeljkovic" <nzeljkovic@xxxxxxxxx>
- Date: Mon, 18 Aug 2008 11:05:23 +0200
Your cut command looks like it's going to give you "/etc/apache2/sites"
every time.
You should sort your result because ls garantees no particular order
unless using ie -lt which is time anyways not numerical.
You don't need expr as long as you are using bash or ksh or zsh or
almost anything but stock sh on sco unix or solaris.
There *shouldn't* be anything else there except sites in format like:
001-site1
002-site2
Etc.. The cut actually works OK, if it doesn't find anything, it just gives
empty string which I address later on.
#!/bin/bash
unalias ls ## grr F*&^* distros...
A=`cd /etc/apache2/sites-enabled ;ls |cut -d- -f1 |sort -n |tail -1`
A=`printf "%03i\n" $((++A))`
In ksh you don't need to spawn a sub shell just to use printf just to
get it back to right-justifid, zero-padded, 3 digits. Nor do you need
the subshell nor any of the processes in the backticks with ls either
as long as we're making any assumptions about the filenames anyways.
There is a quirk that you must start with 001 though.
You can have a file 000-site0, and other files of other forms, just
this script will never see those.
That's exactly what I've been looking for, somewhat, as 000-site0 should be
on servers already, as it will serve default, non named-based access.
#!/bin/ksh
typeset -Z3 A=001
cd /etc/apache2/sites-enabled
while [ -e ${A}-* ] ;do ((++A)) ;done
In both cases $A holds the new/next value at the end
echo Next site is $A
Thanks!
--
Best regards,
Nick Zeljkovic
--
To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx
- Follow-Ups:
- Re: [opensuse] OT: bash F1
- From: Brian K. White
- Re: [opensuse] OT: bash F1
- References:
- [opensuse] OT: bash F1
- From: Nick Zeljkovic
- Re: [opensuse] OT: bash F1
- From: Randall R Schulz
- Re: [opensuse] OT: bash F1
- From: Brian K. White
- [opensuse] OT: bash F1
- Prev by Date: Re: [opensuse] GUI SSH Client
- Next by Date: Re: [opensuse] OT: bash F1
- Previous by thread: Re: [opensuse] OT: bash F1
- Next by thread: Re: [opensuse] OT: bash F1
- Index(es):
Relevant Pages
|