This is a simplified version of a script that runs with one parameter
#!/bin/bash
K1=eval /usr/bin/urlencode "$1" 
echo "$K1" # prints the correct url encoded $1 parameter
echo "$K1" # nothing printed
I looked at other more complex questions/answers to get why the variable lose its content
Moreover, without echoing $K1 anytime, I lose its value if I try to use it in another value like K2="zgrep $K1$DIR. Echoing $K2 prints zgrep $DIR value
 
    