My script functions are not working right

1

Link to my script in question I have been working on a script to help me setup my computer after a clean install, and for the most part it has been running relatively smoothly, but by accident I found out that bash scripts can contain functions and I was elated! Naturally I tried it out on one of my more complex scripts and instead of running as it should I got weird results. Mind you I have not encountered any obvious errors, rather the results are completely unexpected. I have for example put one of the results that I got under the conditions of my wireless card being disabled, and after I call my repo function (my complete script is shown in the link above) it skips the command to copy the files and goes straight to asking if I want to install my wireless card which was never called in any of the functions that should have been called. I have given the result of my example below, but the whole script is not running the way it should under any condition. Please help because I am at a loss. I am running fedora 24 64 bit and I will be happy to provide any of all other wanted information or files that are not included in this question.

    This script operates under the impression that you have an active internet connection.
connect: Network is unreachable
We have found that there is no active internet connection available. Wel will troubleshoot the issue.
Your wireless card is inactive, do you wish to try run the install for it? Y/N

n
Checking the status of your ethernet card.

We found that your ethernet card is active, checking internet connection.
connect: Network is unreachable
We cannot find an active internet connection. Please connect to the network then try again? Y/N

Purpe_Fedora

Posted 2016-09-04T19:54:21.767

Reputation: 67

are you sure your Y/N logic in CopyRepoFiles is correct? there is a copy statement under Y but jumps straight to TestInternet on N. based on the sentence "have repo files already been copied?" this seems backward. – Frank Thomas – 2016-09-04T20:08:50.427

Thanks for the catch your right about that and I fixed it just now, but it doesn't change the weird results I'm getting in the long run. For instance it skips right to the execution of the menu script instead of checking for the internet connection and updating. – Purpe_Fedora – 2016-09-04T20:32:17.807

Hmm I don't know how you got 11. This line is meant to check for an internet connection. I suppose I can try that but unless I accidentally altered each task they are a copy and paste of the original script that worked perfectly without the function. Now since I think about it, do you think I should rewrite it clean with the functions because something might have gotten lost in the conversion? Or is that overkill? – Purpe_Fedora – 2016-09-04T23:49:28.940

You might want to look at How to debug a bash script?

– G-Man Says 'Reinstate Monica' – 2016-09-05T05:41:53.747

I tested your script in my environment (Debian Wheezy x86, Bash version 4.2.37(1)-release) and, after entering Y on the first question, I was asked: Have the repository files been already copied over? Y/N. So, either there's a bug in your version of Bash shell or there's something wrong with its configuration. – Larssend – 2016-09-05T11:24:12.437

that's supposed to be the second question ... or at least that was my intention. Next time I'm on my computer I'll pastebin the original script so you can see what it is supposed to do. – Purpe_Fedora – 2016-09-05T14:38:42.820

As promised here is the link to my original script file I hope this helps clear up any confusion.

– Purpe_Fedora – 2016-09-05T22:10:17.520

No answers