linux - Bash command assigned to variable stays empty -
i have few commands following each other after xargs
. funnily enough command works fine if echo out stdout
. when try assign variable, variable stays empty. see below:
$~ ./somescript | grep -f fc.samples | xargs -i {} sh -c "echo {} | tr '/' '\t' | cut -f9;" sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 $~
trying assign variable , echo results in empty lines:
$~ ./somescript | grep -f fc.samples | xargs -i {} sh -c "sample=$(echo {} | tr '/' '\t' | cut -f9); echo $sample; " $~
i have tried multiple variations of , cannot figure out getting wrong. can spot problem?
thanks!
you need escape $
chars sh -c
command, otherwise $( )
, $sample
part handled current shell rather sh -c
.
... | xargs -i {} sh -c "sample=\$(echo {} | tr '/' '\t' | cut -f9); echo \$sample; "
or can consider using single quotes outer quoting.
... | xargs -i {} sh -c 'sample=$(echo {} | tr "/" "\t" | cut -f9); echo $sample; '
Comments
Post a Comment