Question

I would like to have several text files within my shell script file that unpack into a directory once the script is executed. I've been getting by with 'here-doc' solutions that look like this:

cat>myTextFile.txt<<'EOF'
My Content
EOF

However, my shell scripts are getting larger and are beginning to require more and more files to be unpacked. Basically, I am making a computational pipeline, and want to distribute it as a single shell script, but it needs to expand into several directories/subdirectories/files once run.

Thanks!

Was it helpful?

Solution 2

You can embed in your script a uuencoded tar file and unpack it like this:

tar xf - <<EOF
The uuencoded tarball
EOF

You can encode the data this way:

$ tar cf - src_tree | compress | uuencode src_tree.tar.Z >your_here_doc

then paste the file your_here_doc where 'The uuencoded tarball' line is now, something like this:

$ (echo tar cf - '<<EOF'; cat your_here_doc; echo EOF) >self_expanding_files.sh

OTHER TIPS

How about creating a tar archive and then appending that as binary payload to your script. A really good tutorial can be found here: http://www.linuxjournal.com/content/add-binary-payload-your-shell-scripts

Other options include scripts like makeself which do all of the work for you, making it easier to automate builds.

Can you use a combination of find and cp command? Something like this

find /path/to/your/files -exec cp {} /destination/path \;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top