PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > How to get an piped command resoult in a bash var?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

How to get an piped command resoult in a bash var?

Réponse
 
LinkBack Outils de la discussion
Vieux 07/12/2006, 08h14   #1
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to get an piped command resoult in a bash var?

Hi all

on study bash I 've got an other problem:

================================================== ======
test.sh
#!/bin/bash
if [ -z "$1" ]; then

# using pipe as input : awk $1 symbol is not sh's $1
# also ignore error checking here.

awk '{print $1 }'


else

echo $($1 | awk '{print $1}')

fi
================================================== ======




$echo "10 this is 10" | ./test.sh
10

but

../test.sh '10 this is 10'

do not work

how to do that in right grammar?






  Réponse avec citation
Vieux 07/12/2006, 08h38   #2
RolandRB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get an piped command resoult in a bash var?

Hard to know what you are trying to do but play around with this.

#!/bin/bash
if [ -z "$1" ]; then

# using pipe as input : awk $1 symbol is not sh's $1
# also ignore error checking here.

awk '{print $1 }'

else

echo "$1" | awk '{print $1}'

fi

key9 wrote:
> Hi all
>
> on study bash I 've got an other problem:
>
> ================================================== ======
> test.sh
> #!/bin/bash
> if [ -z "$1" ]; then
>
> # using pipe as input : awk $1 symbol is not sh's $1
> # also ignore error checking here.
>
> awk '{print $1 }'
>
>
> else
>
> echo $($1 | awk '{print $1}')
>
> fi
> ================================================== ======
>
>
>
>
> $echo "10 this is 10" | ./test.sh
> 10
>
> but
>
> ./test.sh '10 this is 10'
>
> do not work
>
> how to do that in right grammar?


  Réponse avec citation
Vieux 07/12/2006, 08h43   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get an piped command resoult in a bash var?

2006-12-7, 16:14(+08), key9:
> Hi all
>
> on study bash I 've got an other problem:
>
> ================================================== ======
> test.sh
> #!/bin/bash


Why call bash for an sh script? That's confusing even though
it'd OK.

> if [ -z "$1" ]; then


if [ "$#" -eq 0 ]

You were testing whether $1 was empty

>
> # using pipe as input : awk $1 symbol is not sh's $1
> # also ignore error checking here.
>
> awk '{print $1 }'
>
>
> else
>
> echo $($1 | awk '{print $1}')


printf '%s\n' "$@" | awk '{print $1}'

>
> fi
> ================================================== ======

[...]

If you replace #! /bin/bash with #! /bin/sh -
you remove the dependency on bash that is not needed here.

--
Stéphane
  Réponse avec citation
Vieux 07/12/2006, 09h06   #4
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get an piped command resoult in a bash var?

> Hard to know what you are trying to do but play around with this.

just study :-)

Sorry for my knowledge,

I understand things like Unix shell ,and UNIX desgin philosophy only 2 month
also I am not computer specialty

before that , when I want to solve some problem ,
I always using VBScripts.

and now I found another way- shell programming
pretty cool,like playing toy bricks.

so the situation is I have concept of what I want to solve (modeing),
but I have no idea how to do that in shell. especially in grammar details.

I think it's good news for me there's so much warmhearted people here
:-)

appreciate



  Réponse avec citation
Vieux 07/12/2006, 09h24   #5
RolandRB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get an piped command resoult in a bash var?


key9 wrote:
> > Hard to know what you are trying to do but play around with this.

>
> just study :-)
>
> Sorry for my knowledge,
>
> I understand things like Unix shell ,and UNIX desgin philosophy only 2 month
> also I am not computer specialty
>
> before that , when I want to solve some problem ,
> I always using VBScripts.
>
> and now I found another way- shell programming
> pretty cool,like playing toy bricks.
>
> so the situation is I have concept of what I want to solve (modeing),
> but I have no idea how to do that in shell. especially in grammar details.
>
> I think it's good news for me there's so much warmhearted people here
> :-)
>
> appreciate


Are you trying to do something along these lines?
http://www.datasavantconsulting.com/...ripts/derprogs

  Réponse avec citation
Vieux 07/12/2006, 13h14   #6
key9
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to get an piped command resoult in a bash var?


> Are you trying to do something along these lines?
> http://www.datasavantconsulting.com/...ripts/derprogs


no , but that's a great :-) thank you
actually I want to design a mechanism which can simulate network node's
actions.

First I put everyting into a very large c++ application,

That almosted kill me. more than 200 classes which make one application and
accept input and get the resoult.
which still can not run ,I am sorry to say.

finally I got the idea : who cares how fast the scripts run , I just want
the simulate resoult to me judge the next step.

so shell scripting is the best way. since I've got no experience about shell
coding , so grammar will be the biggest problem.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h32.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,16221 seconds with 14 queries