Francesco Pretto wrote:
> I'm sorry if this isn't the wrong place to ask, but I couldn't find an user
> mailing list.

The help-gnu-ut...@gnu.org mailing list is available for generic help
questions such as this.

> My question is if it's possible to manipulate strings without
> using  variables. Or, how to do the following in one line without using a
> variable:

The shell itself needs a variable to perform the replacement
operation.  But you don't need to structure your task that way.

> FILENAME=$(ls | tail --lines=1)

Note that your locale setting (LANG, LC_ALL) affects sort ordering.

> echo ${FILENAME%.*}

Since you already have a pipeline you could do this:

  FILENAME=$(ls | tail --lines=1 | sed 's/\.[^.][^.]*$//')

Or with GNU sed using the \+ extension:

  FILENAME=$(ls | tail --lines=1 | sed 's/\.[^.]\+$//')

I assume that 'ls' isn't what you actually are doing, that you have
reduced the test case to something smaller (thank you for that!)
because the shell can list the directory itself.

  for f in *;do FILENAME=$f; done
  ( Or even: for FILENAME in *;do : ; done )

And you could then slip in your variable manipulation right there.

  for f in *;do FILENAME=${f%.*}; done
  echo $FILENAME

Bob


Reply via email to