Skip to main content
added 1 character in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

or, if you just want to test for an empty value,

if [ -z "$ARCHIVE_PATH" ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS).

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS). In fact, more than half the script is taken up by statements verifying configuration settings.

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

or, if you just want to test for an empty value,

if [ -z "$ARCHIVE_PATH" ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

added 1 character in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scriptscripts are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS).

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-script are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS).

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-scripts are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS).

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

added 424 characters in body
Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-script are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS).

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-script are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Yes, the return statement can only be used to return an exit status from a shell function or a dot-script (a script being sourced using either . (dot) or source in shells that support that alias for .). Shell functions and dot-script are very similar in that respect.

The code that you show contains a return statement as its last executable statement, and this may be what throws the error if you ran the script as an ordinary script.

It may well be that your script is supposed to be executed as

. ./script.sh

rather than as

./script.sh

or that another script is supposed to do that (it's unknown). If you do run the script with the dot command (or source in e.g. bash), note that you will be left in /ERQ/100/DM/SCRIPTS after the end of the execution of the script (since this is where the script changes the working directory upon exiting).

Note also that the script uses some strange code to do ordinary things. For example, to test whether $ARCHIVE_PATH is defined it does

VARCHECK=`echo $ARCHIVE_PATH | wc -w`
if [ $VARCHECK = "0" ]

This test would not test whether it was undefined but whether it was empty (or contained only characters from $IFS).

Instead, one could use

if [ "${ARCHIVE_PATH-is unset}" = "is unset" ]

or, in bash,

if [ ! -v ARCHIVE_PATH ]

The script also uses ls in multiple places to get lists of files, which is less than ideal.

Source Link
Kusalananda
  • 355.8k
  • 42
  • 735
  • 1.1k
Loading