RE: [opensuse] OT: bash F1



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



Relevant Pages

  • Re: ksh: why use expr?
    ... > I frequently see statements like this in my company's ksh scripts. ... > What is the purpose of including the expr command in this case? ... try the various codes with values of DBUP like: ...
    (comp.unix.shell)
  • Re: ksh: why use expr?
    ... >>I frequently see statements like this in my company's ksh scripts. ... >>What is the purpose of including the expr command in this case? ...
    (comp.unix.shell)
  • File sorting question
    ... I need a quick way to sort a file (ksh, awk, perl are all fine). ... The sorting criteria is as follows: First, based on the second field ...
    (comp.unix.shell)
  • Re: File sorting question
    ... >I need a quick way to sort a file (ksh, awk, perl are all fine). ... >that in conjuction with the primary sorting criteria. ...
    (comp.unix.shell)
  • Re: time command, and $-, in Bourne shell
    ... If you can use ksh, you don't need expr: ... And you certainly don't need it twice: ... And before posting a reply from Google Groups, ...
    (comp.unix.shell)