Using awk within kdialog

hi,

I'm trying to built a script (in tcsh) that makes use of kdialog and return the choice to a variable:

#
!/bin/tcsh -f
alias dirlist 'unalias ls; ls -l \| awk \'\/\^d\/\{print\ \$9\}\''
set choice = `kdialog --combobox "choose a folder:" `dirlist``

but I cannot make this work.

Could anyone help me with this?

thanks very much in advance.

Please use "code" tags (at the top of the Wiki editor)!

The | within ticks must not be quoted in order to work as a pipe, and tcsh has problem with ticks within ticks, so you must use other escapes.

alias dirlist 'unalias ls; ls -l | awk /\^d/\{print\ \$9\}'

There is no need to quote the / character.
A quoted external command bypasses aliases, so you can do

alias dirlist '\ls -l | awk /\^d/\{print\ \$9\}'

--
And here is the trick for ticks within ticks: an escaped \' outside the 'string' .

alias dirlist '\ls -l | awk '\''/^d/{print $9}'\'

thanks,MadeInGermany.

the alias command worked just fine.

Would you have any ideas on how to make the kdialog commend work?

thanks in advance.

tcsh cannot properly handle backticks within backticks.
You can store the first backtick expression in a variable:

set dirlist=`dirlist`
set choice=`kdialog --combobox "choose a folder" $dirlist:q`

Or without the alias and its quoting problems

set dirlist=`\ls -l | awk '/^d/ {print $9}'`
set choice=`kdialog --combobox "choose a folder" $dirlist:q`

tcsh is a bad shell, consider bash instead!
kdialog seems to have a delay when not working on a terminal.

Thanks, MadeInGermany

it worked perfectly, both options.

best regards,

ncfc01