Bash Brace Expansion and cp

beingalex

I have this shell script:

#!/bin/sh

src=/a/really/long/dirctory/sd65asdasd/
dest=/var/www/api

# Remove everything
# Could maybe copy it as a backup (?)
sudo rm -rf $dest

# Start building new file structure
sudo mkdir $dest
sudo chown user:user $dest
cp -R $src/bin /$src/config $src/plugins $src/src $src/webroot $dest

cp $src/composer.{json,lock,phar} $src/gulpfile.js $src/index.php $dest 

But I am getting:

cp: cannot stat '/a/really/long/dirctory/sd65asdasd/composer.{json,lock,phar}': No such file or directory

If I do a simple copy directly in the commandline without the bracket expansion it works without problem.

Any ideas?

echo $BASH_VERSION  = 4.4.19(1)-release
user1686

You're not actually running the script under Bash; you're running it under /bin/sh.

/bin/sh is only required to provide the baseline "POSIX shell" features, so while on one system it may be Bash, on others it may not be. For example, Debian almost always uses the dash shell as /bin/sh.

The goal of dash is to be fast and minimal; brace expansion is not a standard feature, so Dash doesn't provide it (like it doesn't provide many other syntax features, like arrays).

Similarly, on other distributions the shell might be busybox-ash, or Korn shell (which actually does support {} expansion), or even zsh.

To actually use Bash, change the script's header to #!/bin/bash or #!/usr/bin/env bash.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Brace expansion with numbers in bash

From Dev

BASH brace expansion algorithm

From Dev

Brace expansion with numbers in bash

From Dev

Bash Brace Expansion & Variables

From Dev

bash - brace expansion not expanding?

From Dev

Nested brace expansion mystery in Bash

From Dev

Bash Brace Expansion in Systemd ExecStart

From Dev

bash in-line brace expansion

From Dev

bash in-line brace expansion

From Dev

Nested brace expansion mystery in Bash

From Dev

`seq` and bash brace expansion failing

From Dev

Change separator/delim in bash brace expansion

From Dev

Brace expansion with step increment not working bash

From Dev

Bash brace expansion after a path slash

From Dev

Bash brace expansion after a path slash

From Dev

bash shellcheck issue with variables in brace expansion

From Dev

Brace expansion with step increment not working bash

From Dev

Can I use a variable in a Bash brace expansion?

From Dev

In bash, is it possible to use an integer variable in a brace expansion

From Dev

Bash brace expansion to remove part of filename

From Dev

Change separator/delim in bash brace expansion

From Dev

Bash brace expansion with variables for pattern matching

From Dev

Can I use bash brace expansion in for loop?

From Dev

Can't combine brace expansion with parameter expansion in bash

From Dev

How does bash differentiate between brace expansion and command grouping?

From Dev

How to output comma-separated strings using bash brace expansion

From Dev

Prefixing an output file in bash with brace expansion after sox processing

From Dev

brace expansion command not recognized

From Dev

Brace expansion in python glob

Related Related

HotTag

Archive