I wrote a simple program called sarcasm that simply takes all its arguments, concatenates them, and converts the resulting string use 'aLtErNaTiNg CaPs'. I have written a simple one-line shell script that will let me use dmenu to enter text, run that text through this program, and copy the result to my clipboard. Here is what I have:
echo "dmenu -p 'Text: '" | sh | read var ; [[ -n "$var" ]] && echo -n $var | xargs sarcasm | xclip -selection clipboard
It is supposed to:
- Prompt me for text using dmenu
- If (and only if) I entered any text, run it through the
sarcasmprogram and copy the result to my clipboard
It works fine when I run that exact command with zsh, or if I run it in a script using zsh (i.e. the shebang is #!/bin/zsh), but when I run it with bash, it doesn't copy anything to my clipboard. What part of this is zsh-only, and what is the bash equivalent (if there is one)?
[[ .. ]]which is irrelevant) - nothing is zsh specific. I suspect your ENVIRONMENT is different when you run from bash and it does not have the X environment present (this is a strong suspicion, but cannot be verified without seeing your environment)[[is not POSIX, but it is a legal bash operator.sarcasmto identify the issue. Or it could be something with your environment. Have you triedecho -n 'test' | xclip -selection clipboardwith an interactive bash shell, to try to rule things out?echo $varmay produce slightly different results. Sayvarcontains the textA B(4 embedded spaces) , then it would produceA Bunder zsh, butA B(1 space) under bash.