Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  26] [ 0]  / answers: 1 / hits: 55944  / 3 Years ago, mon, august 23, 2021, 2:39:22

I'm writing a script to copy some files around, and trying to use shopt -s dotglob to enable cp to copy dotfiles like .jshint and whatnot.



I can run shopt -s dotglob directly at a bash prompt with no error. However, running the script throws the error:



script.sh: 81: script.sh: shopt: not found


I'm running this script in bash shell, with the shebang header #!/usr/bin/env bash. Error line:



shopt -s dotglob
cp -r $TEMP/img/* $TARGET/img/
cp -r $TEMP/js/* $TARGET/js/
cp -r $TEMP/less/* $TARGET/less/


Not finding anything helpful on google, any idea what the problem is here?


More From » bash

 Answers
0

To form an answer from the comments:



Many people out of habit run their scripts with sh instead of bash. This is a good practice if portability is a concern, but many people do so because they're copying something they've seen without understanding it.



Unless your script needs to run on a non-desktop Linux system (e.g., running shell scripts on Android devices is quite different), I recommend using the Bash shebang line at the beginning:



#!/bin/bash


This line, when it's the first line in the script, determines which interpreter (shell such as bash or sh, Python, etc.) is called to execute it. If you use the above line, you'll get the same behavior (almost) as you do from the command line, assuming you use the default shell. If for reasons of portability or preference you use a different shebang line, be aware that you'll have to consult the documentation for the shell you've referenced, even if the shell you reference is a symlink to Bash.


[#35913] Monday, August 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
whoppinolo

Total Points: 93
Total Questions: 113
Total Answers: 107

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
whoppinolo questions
Tue, Feb 14, 23, 08:30, 1 Year ago
Wed, Sep 28, 22, 06:56, 2 Years ago
Fri, May 27, 22, 01:55, 2 Years ago
Tue, Oct 12, 21, 09:33, 3 Years ago
;