I am running two Linux commands and I want to put the resulting values together in a filename with no spaces and a dot separating the two values. So far, I've got this:pid=`sudo dmidecode -s system-product-name`vid=`sudo dmidecode -s system-version`# cleanup spaces in $pid and $vidfilename=$pid.$vid.tar.gzHow can I clean up the spaces in the two variables?
filename with no spaces from two command lines
bash;filenames;string
You can use bash Pattern substitution (search for that string in the man page for details).filename=${pid// /}.${vid// /}.tar.gzThe double slash means replace all occurrences of the pattern. The space between the double slash and the next slash is the pattern. The replacement pattern is after the last slash, which in this case is empty. You can remove the final slash, but I prefer it for clarity as it brackets the space.