better way ?

better way ?

Post by Scott Onofr » Thu, 28 Mar 1996 04:00:00



Is there a better way to do this ?

I want to generate dependencies for a Makefile. Forexample if I have a
list of files, PROGS="1 2 3 4".

I want the following output

1 \
2 \
3 \
4

 - - - - - - - - - -  please review and give advice - - - -
 first better answer gets a pop. before responding make sure that
 I have not posted saying there was a winner ! :-)

PROGS="1 2 3 4"

# Prerequisites: must set a variable TPROGS first.
#
# Will print the head of a list and then echo the head
# with a backslash if it is not the end of the list. If
# it is the end of the list it will not print the backslash.
#
# for example:
#
# TPROGS="1 2 3 4"
#
# echo_head_and_conditional_backslash $TPROGS   -> 1 \
# echo_head_and_conditional_backslash $TPROGS   -> 2 \
# echo_head_and_conditional_backslash $TPROGS   -> 3 \
# echo_head_and_conditional_backslash $TPROGS   -> 4
#
# TPROGS gets shortened each call..
#
echo_head_and_conditional_backslash () {
      head=$1
      shift
      TPROGS=$*
      if [[ $TPROGS = "" ]];then
          echo $head
      else
          echo $head  \\
      fi

Quote:}

TPROGS=$PROGS
for i in $PROGS
do
  echo_head_and_conditional_backslash $TPROGS
done

--

Scott Onofrio
________________________________________ Hewlett-Packard (M/S AU100)

Phone: 970-679-3105                      815 Southwest 14th Street
Fax:   970-679-5961                      Loveland, Colorado 80537

 
 
 

better way ?

Post by Grant Reab » Thu, 28 Mar 1996 04:00:00




>Is there a better way to do this ?

>I want to generate dependencies for a Makefile. Forexample if I have a
>list of files, PROGS="1 2 3 4".

>I want the following output

>1 \
>2 \
>3 \
>4

> - - - - - - - - - -  please review and give advice - - - -
> first better answer gets a pop. before responding make sure that
> I have not posted saying there was a winner ! :-)

(longish and not Bourne shell program elided)

# may fail if $PROGS contains regexp-special characters
# will fail if $PROGS contains duplicate elements
for arg in $PROGS
do
  if echo $PROGS | grep $arg\$ >/dev/null 2>&1
    then echo $arg
    else echo $arg \\
  fi
done

# a more robust way
count=0
for arg in $PROGS
do
  count=`expr $count + 1`
done

for arg in $PROGS
do
  count=`expr $count - 1`
  if [ $count -eq 0 ]
    then echo $arg
    else echo $arg \\
  fi
done

These scripts should run on anything.  On many systems you can use grep
-s instead of redirecting grep.  On some really old systems you might
need to use expr to test for count equal to zero.

Grant

 
 
 

better way ?

Post by Scott Onofr » Thu, 28 Mar 1996 04:00:00


Got a winner...

: Is there a better way to do this ?

: I want to generate dependencies for a Makefile. Forexample if I have a
: list of files, PROGS="1 2 3 4".

: I want the following output

: 1 \
: 2 \
: 3 \
: 4

:  - - - - - - - - - -  please review and give advice - - - -
:  first better answer gets a pop. before responding make sure that
:  I have not posted saying there was a winner ! :-)

: PROGS="1 2 3 4"

: # Prerequisites: must set a variable TPROGS first.
: #
: # Will print the head of a list and then echo the head
: # with a backslash if it is not the end of the list. If
: # it is the end of the list it will not print the backslash.
: #
: # for example:
: #
: # TPROGS="1 2 3 4"
: #
: # echo_head_and_conditional_backslash $TPROGS   -> 1 \
: # echo_head_and_conditional_backslash $TPROGS   -> 2 \
: # echo_head_and_conditional_backslash $TPROGS   -> 3 \
: # echo_head_and_conditional_backslash $TPROGS   -> 4
: #
: # TPROGS gets shortened each call..
: #
: echo_head_and_conditional_backslash () {
:       head=$1
:       shift
:       TPROGS=$*
:       if [[ $TPROGS = "" ]];then
:         echo $head
:       else
:         echo $head  \\
:       fi
: }

: TPROGS=$PROGS
: for i in $PROGS
: do
:   echo_head_and_conditional_backslash $TPROGS
: done

: --

: Scott Onofrio
: ________________________________________ Hewlett-Packard (M/S AU100)

: Phone: 970-679-3105                      815 Southwest 14th Street
: Fax:   970-679-5961                      Loveland, Colorado 80537

--

Scott Onofrio
________________________________________ Hewlett-Packard (M/S AU100)

Phone: 970-679-3105                      815 Southwest 14th Street
Fax:   970-679-5961                      Loveland, Colorado 80537

 
 
 

better way ?

Post by Randal L. Schwar » Fri, 29 Mar 1996 04:00:00


Scott> Is there a better way to do this ?

Scott> I want to generate dependencies for a Makefile. Forexample if I have a
Scott> list of files, PROGS="1 2 3 4".

Scott> I want the following output

Scott> 1 \
Scott> 2 \
Scott> 3 \
Scott> 4


--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying

Web: <A HREF="http://www.teleport.com/~merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me

 
 
 

better way ?

Post by Jeffrey Ko » Fri, 29 Mar 1996 04:00:00




>Is there a better way to do this ?

>I want to generate dependencies for a Makefile. Forexample if I have a
>list of files, PROGS="1 2 3 4".

>I want the following output

>1 \
>2 \
>3 \
>4

Ksh93:          print "${PROGS//+([$IFS])/$' \\\n'}"

--

Jeff Korn

 
 
 

better way ?

Post by Brian S Hile » Fri, 29 Mar 1996 04:00:00


: ...
: Is there a better way to do this ?
: ...

The ever-reliable and mucho-portable sed solution:

echo '1 2 3 4' | sed \
's/ / \\\
/g'

You can get clever, e.g. by parsing only IFS characters, etc, as you wish.

-Brian
--
   ,---.     ,---.     ,---.     ,---.     ,---.     ,---.     ,---.  
  /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \   /  _  \  

__,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.___,'   `.__

 
 
 

1. i know there are better ways....

UNZIPDIR="/home/ftproot/www/publications/incoming/"
UNZIPDIR=`echo "$UNZIPDIR" | sed -e "s/incoming\///g"`

Hi all ~

this is the best (so far) i have come up with to chop off the
"incoming/" part from UNZIPDIR.

I know there's got to be a couple of way more elegant ways to do
this...

Please share,

thanks,
Kai

2. tar Win95 Partition to Tape?

3. ssh1 password-less RSA login - how secure is that? better ways?

4. PAP connection

5. Red Hat Results - better and better

6. squid on AIX

7. Is Windows NT a better VMS or a better Unix ?

8. Problem with Windows 95 Proxy (I know...)

9. better hw -> better sys

10. Is AMD better or Intel better for Linux?

11. Any other ways to link a linux machine to a network

12. How do i disable all ways to get access to the dos prompt on startup?

13. newbie to discussions, are there other ways to discuss?