For some reason, the script is looking for a command named "-". The fourth line of theh below output indicates that there's a problem. + echo 'It takes seconds to complete this task.' Showtop: line 4: -: command not found <= oops! Here's an example of using the bash -x form of debugging for a script that is intended to display the top lines of a file: $ bash -x showtop You can also use both with -xv as you bash argument (i.e., bash -xv). This means that you will see the entire script and then its output as it is run. The -v bash option works similarly to -x, but it displays each line in a script as it being read. To do this, add "set -x" before the section of the script you want debug and "set +x" to turn debugging off after that section. ![]() You can also elect to turn debugging on for only a portion of a script. Just remember to remove the "-x" once your debugging is complete. Putting the -x option in the shebang line means you don't have to type "bash -x scriptname". Or you can insert the -x into the "shebang line" at the top of the script: #!/bin/bash -x You can start your script like this: $ bash -x myscript This allows you to see which commands are working as expected and which are not. It helps in debugging by displaying each line in a script as it is being executed. You can turn on what is often called "debug mode" by using -x as an argument to bash. ![]() This will help you verify that they're working properly or pinpoint any lines in the script that might be causing problems. Check the type of an argument if * ]] thenĬheck that a file exists if thenĪnother way to test scripts it to turn on debugging. Notice that a usage statement is generated if the arguments don't match what is expected, and the script is then exited. Here are some examples of implementing these checks. To help ensure that a script won't run into runtime problems, make sure it checks that the correct number of arguments are being provided and that any files provided as arguments actually exist. Go back and fill in the details after you put the basic command framework in place. For i in list while case "$1" in if thenĭo do str1) cmd cmds cmds cmds *) cmd else done done esac cmds fi
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |