Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

The goal is to create a bash one line command that can be copied and pasted - for instance published on a web forum - and then patches files. See it as a way to distribute a patch file by copy and paste it to the command line.

On the source system:

  1. a patch file is used as input,
  2. and another bash command should be used to create the ouput.

Currently this is done via:

$ oldifs=$IFS;printf '\n{ ';while IFS= read -r p;do printf 'echo %q; ' "$p";done < custom.patch;printf ' }\n\n';IFS=$oldifs

That creates output like:

echo \ //=\ require\ xyz.js; 
echo @@\ -81\,7\ +80\,6\ @@; 
echo $' \t\t\tchild.currentlyBackingUp = $(\'.dashboard-currently-backing-up\', element).dashboardBackup({type: this.type});'; 

This can be used as input in a one line patch command on the target system like:

patch < { echo \ //=\ require\ xyz.js; echo @@\ -81\,7\ +80\,6\ @@; ... }

So far so good, until the source patch file contains a bang (!) character. Then the printf creates escaped output like:

echo $' \t\t\tif (!cp.user.isMyUserQueryLimited()) {'; 
echo $'-\t\t\t\tif ( === "map-tab" && !serverEnv.queryLimited) {'; 
echo $' \t\t\t\tif (!hosted) {';

When pasting such a line to a bash command line, it results in:

#-bash: !cp.user.isMyUserQueryLimited: event not found

How to programmatically create text stream data using a bash command that can be copied and pasted, that outputs a stream of text data, by a command that can be pasted into another bash command prompt where history expansion is enabled (histexpand = on)?

share|improve this question
Look through Stephane's A's to these Q's, I seem to remember him answering a Q very similar to this your. Here's a link to his Q's about paste, which I think is what it was about: – slm Nov 21 '13 at 22:18
@slm Thanks for you comment. In Stephane's 31 answers about paste, of which 50% I did completely read, I could not find any hints that help me to create text streams that can be pasted. – Pro Backup Nov 21 '13 at 23:32

Your Answer


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

Browse other questions tagged or ask your own question.