0

I just try to put variable inside variable but it doesn't work... How can i Fix it?

DEL=$(find . -type f | sed "s/^.*\///g" | sed -n '/\./p' | sed "s/.*\.//g" | uniq)
EL=$(${DEL} | tr '\n' ',' | sed 's/,$//')
4
  • 1
    try EL=$(echo ${DEL} | tr '\n' ',' | sed 's/,$//') Commented Mar 18, 2016 at 23:36
  • well... it prints something, but still it doesn't put comma between space. :) Commented Mar 18, 2016 at 23:41
  • 1
    @user3463055 echo ${DEL} prints all elements on a line, that's why tr can't replace '\n' with ','. I think you can workout what you need on your own, besides you didn't mention the desired output in your question. :) Commented Mar 18, 2016 at 23:45
  • 1
    I want to print all file extensions and between spaces I need to put commas... But thank you for your reply, I have already found a solution. :) Commented Mar 18, 2016 at 23:52

1 Answer 1

1

You can try

EL=$(tr '\n' ',' <<< "$DEL" | sed 's/,$//')

or

EL=$(echo "$DEL" | tr '\n' ',' | sed 's/,$//')
Sign up to request clarification or add additional context in comments.

3 Comments

The first will work. The second would work if you use echo "$DEL" but as written (without double quotes), there'd be just one newline in the input to tr, right at the end, and the sed would remove the one comma that tr adds (which is really not very productive).
@JonathanLeffler - Thanks for pointing this out, I have modified it.
YW: I should also have noted that the shell must be Bash (or a shell that supports here-strings with <<< — POSIX shells don't support that). The second works with most shells.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.