Using pipes, one can create files with simple shell built-ins.
{ echo "#!/bin/bash" \
echo "echo Hello, World!" \
} > helloworld.sh
With chmod
these can then be made executable.
$ chmod 755 helloworld.sh
$ ./helloworld.sh
Hello, World!
I wonder whether it is possible to save the chmod
step. Already, I found that umask
cannot do the job. But perhaps someone knows an environment variable, bash trick, program to pipe through or other neat way to do it.
Is it possible to have the file created with the executable bit already set?
touch file; chmod u+x file; dostuff >> file; ./file
?chmod
step?chmod
is to reduce changes to a single point. When the file name or path should later change, the change would than only affect this single line. Defining a variable keeping it would be an alternative, but add an otherwise unnecessary line./opt
) has to be created via pipe, then made executable, which makes exactly these two uses. The one who calls the script then, is the user who installed the package.