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
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.
Comments