Whilst you can use the line from your question it's quite inefficient as you're redirecting your script through two pipes. You can simplify it by just using (as @Wimm pointed out):
cat myfile.sh > newbash.sh
However, if you're installing the scripts I'd suggest you look into using the install command instead as this gives you finer control over the process by letting you set the permissions and UID/GID for the file and so on. Using cat will not copy any of metadata for your script; cp is a little better but you'd probably need extra commands like mkdir -p, chown and chmod to get thing just right. With install you could say something like:
install -Dp -v -o root -g staff -m 0755 myfile.sh /path/to/install/at/newbash.sh
This will...
- create any missing directories along the destination path (
/path/to/install/at)
- make a copy of
myfile.sh, called newbash.sh, at the destination
- set the timestamp of
newbash.sh to be the same as myfile.sh
- change the owner of
newbash.sh to root and the group staff
- set the file permissions to
0755 (or -rwxr-xr-x if you prefer)
catorcpcreate the file under the current user's permissions? I would hate to useinstalland then not be able to run it without escalating considering these Pi's are designed to be mostly hands off. – T. Cubbin Feb 01 '19 at 20:29install:-o pi -g pifor example. I didn't mean to imply that usingcpis wrong only that there may be a better tool available with more control should you need it. I believe you can get the same outcome by usingcp -p myfile.sh newbash.shhttps://linux.die.net/man/1/cp – Roger Jones Feb 02 '19 at 00:03