Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #17017

Re: bash script problem ?

From no.top.post@gmail.com
Newsgroups comp.os.linux.misc
Subject Re: bash script problem ?
Followup-To comp.os.linux.misc
Date 2016-03-16 16:51 +0000
Organization A noiseless patient Spider
Message-ID <ncc2v7$gbt$1@dont-email.me> (permalink)

Followups directed to: comp.os.linux.misc

Show all headers | View raw


In article <>, dave.gma+news002@googlemail.com.invalid (Dave Sines) wrote: 

> 
> [ slackware- and debian-specific groups dropped ]
> 
> no.top.post@gmail.com wrote:
> > I want to launch from a bash script:
> >  xterm -e mc  <Path1> <Path2>
> > where <Path1> = dirname `head -1 /root/.mc/filepos |awk '{print $1}'`
> >  and  <Path2> = dirname `head -2 /root/.mc/filepos |awk '{print $1}' | tail -1`
> > 
> > I.e. the 1st token of the 1st & 2nd line of /root/.mc/filepos are args of mc
> > The following 4 lines fail:-
> >  Path1=dirname `head -1 /root/.mc/filepos |awk '{print $1}'`
> 
>   Path1=`dirname \`head -n 1 /root/.mc/filepos | awk '{ print $1 }'\``
> 
> >  Path2=dirname `head -2 /root/.mc/filepos |awk '{print $1}' | tail -n 1`
> 
>   Path2=`dirname \`head -n 2 /root/.mc/filepos |awk '{print $1}' | tail -n 1\``
> 
> The $( ... ) form is preferred:
> 
>   Path1=$( dirname -- $( head -n 1 /root/.mc/filepos | awk '{ print $1 }' ) )
>   Path2=$( dirname -- $( head -n 2 /root/.mc/filepos | awk '{ print $1 }' | tail -n 1 ) )
> 
> Although the above lines can also be
> 
>   { read Path1 x ; read Path2 x ; } < /root/.mc/filepos
>   Path1=$(dirname -- "$Path1")
>   Path2=$(dirname -- "$Path2")
> 
> >  xterm -e mc `dirname $Path1`
> >  xterm -e mc `dirname $Path2`
> > ---
> > dirname `head -1 /root/.mc/filepos |awk '{print $1}'`
> >    and
> > dirname `head -2 /root/.mc/filepos |awk '{print $1}' | tail -1`
> >    evaluate correctly, and so does:
> > xterm -e mc /root/.wilybak /var
> 
> It looks as if you're trying to do this:
> 
>   { read Path1 junk ; read Path2 junk ; } < /root/.mc/filepos
>   xterm -e mc "$(dirname -- "$Path1")" "$(dirname -- "$Path2")"
> 
> > 
> > I've been blaming bash's ad-hoc syntax:
> >  input/output from the left or right ...etc.
> > but this task isn't "straight piping" because you first get 2-parameters,
> > and then pipe-them both to mc.
> 
> There's no pipe to mc.  The shell captures the output of the commands
> between the `` delimiters and substitutes the delimited text with the
> captured output.
 =======================
That's quite amazing!
Path1=`dirname \`head -n 1 /root/.mc/filepos | awk '{ print $1 }'\``  
Path2=`dirname \`head -n 2 /root/.mc/filepos |awk '{print $1}' | tail -n 1\``
echo "A=" $Path1 $Path2

Path1=$( dirname -- $( head -n 1 /root/.mc/filepos | awk '{ print $1 }' ) )
Path2=$( dirname -- $( head -n 2 /root/.mc/filepos | awk '{ print $1 }' | tail -n 1 ) )
echo "B=" $Path1 $Path2

{ read Path1 x ; read Path2 x ; } < /root/.mc/filepos
Path1=$(dirname -- "$Path1")
Path2=$(dirname -- "$Path2")
echo "C=" $Path1 $Path2

{ read Path1 junk ; read Path2 junk ; } < /root/.mc/filepos
echo "xterm-e mc" "$(dirname -- "$Path1")" "$(dirname -- "$Path2")"
#  xterm -e mc "$(dirname -- "$Path1")" "$(dirname -- "$Path2")"

!! your COMPLETELY new syntax is un-nerving.
Where is it documented?

== TIA.

Back to comp.os.linux.misc | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: bash script problem ? no.top.post@gmail.com - 2016-03-16 16:51 +0000
  Re: bash script problem ? dave.gma+news002@googlemail.com.invalid (Dave Sines) - 2016-03-17 00:20 +0000

csiph-web