Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've got this script:

for f in "$@"
do
    q=${f#*Media/Music/}
    echo q
done

All I want to do is set q to f after Media/Music/.

But it just echoes nothing.

If I do echo "${f#*Media/Music/}" then it gives me my result.

Why isn't this working?

share|improve this question

2 Answers

You should use $ or ${} to get a variable.

for f in "$@"
do
    q=${f#*Media/Music/}
    echo $q   # here use $q it'll work fine.
done
share|improve this answer

You need to add $ for printing the variable.It is printing nothing because by default the value of a variable is initialized to NULL. You need to use

echo $q 
instead of

echo q
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.