The first active code line in AudioScope.sh is set -u .
This causes a complete exit if a variable is used/found but has not been allocated at the start of the program.
However, apart from writing code to do the task, is there a switch to to check which variables have been allocated but have not been used in the remainder of the code?
I have checked the WWW and there is nothing. I have also read the bash manual and can't see any reference.
iMac, OSX 10.11.4, bash version:-
GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15)
Copyright (C) 2007 Free Software Foundation, Inc.
Maybe it helps to grep out the variable assignments from your script?
Here is a clumsy attempt:
Then try to find the $var references in a loop, and print if not found
Yet it does not know if a var= is within a 'string' or "string" i.e. is not an assignment in the shell...
This User Gave Thanks to MadeInGermany For This Post:
I have no knowledge of Perl so will have study the syntax.
I did try your two code snippets however and it didn't seem to pick out variables, whether in stand alone or string mode, as a single occurence of said 'string' "var=".
I was expecting to write code but got sample code written for me. Thanks...
Hi drl...
Just come on so not had time to look at and try your code snippets as yet.
I don't intend to alter my style of coding from my very first post of AudioScope.sh even though it may look a little primitive now. I have the bash -n filename switch to check the syntax and that is all I need here.
However as MadeInGermany has suggested 'var=' could be anywhere in any line of the code; but so long as there is only one of them then that particular 'var=' can be considered redundant. I will also check to see if there are two of the said variable(s) just in case there is a reference to a redundant variable inside a comment.
Thanks both so far...
---------- Post updated at 01:56 PM ---------- Previous update was at 01:22 PM ----------
......and it gave these results.
It found wave_form but this is used several times so not quite accurate...
As for the rest my code is designed to be as "bash" backwards compatible as is possible, and I am ignoring the 'printf' statements as errors.
I guess I could change the arithmatic and backticks to up to date methods but as I have quoted I want to keep the style as I originally learnt it, not waht I know now.
I am designing this project around a now 3 year 9 month old MBP OSX 10.7.5 and bash version:-
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)
Copyright (C) 2007 Free Software Foundation, Inc.
Thanks drl for the pointer. A good find by you and extremely useful but I had no idea how to search for it...
As for the rest my code is designed to be as "bash" backwards compatible as is possible, and I am ignoring the 'printf' statements as errors.
Backwards compatible with what? It's already meant for bash, so I assume you mean sh... You store binary data in shell variables -- I wouldn't trust that to work in anything but brand-name BASH, and very modern BASH at that.
The problems it flags with printf are all legit, btw. What would happen if your binary data included a meaningless % character, just incidentally? printf would bomb, that's what, because % is not meaningless to printf. printf "%s" "$data" avoids that problem.
However, apart from writing code to do the task, is there a switch to to check which variables have been allocated but have not been used in the remainder of the code?
You already have been given very good advice here, so there is little for me to add - which is why i can as well quit pretending to be helpful and start to outright annoy you:
i think you tackle this from the wrong side alltogether!
Every software engineer learns about structured programming and its values and writing reusable pieces of code, yada, yada. But as every experienced software engineer can tell you structurisation - that is, breaking down the code to simple functions - is not only about reusing pieces of code and all the other tenets. One of its greatest benefits is that it breaks down long parts of the code into small manageable "chapters".
A former colleague of mine, principal senior coder in a large software project, even opined that a function - any function - that is longer than a screen full (he uses the same 80x40 xterm windows i prefer) should be broken down into parts, if not for anything else than for clarity of reading. Now, i think this strict stance is a bit of throwing the baby out with the bath water, but i can understand his sentiment. I try to apply this to my shell scripting all the time and - apart from a few exceptions, like commandline handling in scripts with many options - my functions are mostly fitting on one page of the 80x40 xterm i prefer.
Now, shell programming allows for a lot of bad behavior: undeclared variables made out of thin air, no real distinction between locals and globals and so on. I try to always work as strict as possible, meaning:
if i use a variable, i write a "typeset"-statement declaring it, using "typeset -i" if i intend to use it as an integer.
I admit publicly here that i am a devout user of Hungarian Style Notation, adapted to my needs as a shell programmer: i use, for instance, "f" as a prefix for file/directory names, even if there is no real datatype of a "path", whereas strings that can contain whatever are prefixed "ch" ("char" obviously). I also use "l" for switches, even though they are integers but should only contain 0 or 1. But it doesn't matter so much what you use: be consistent with yourself! If you use UPPERCASE for variables (personally i hate that, but that is just me) then ALWAYS use it - not sometimes this way and sometimes the other.
I ALWAYS stay away from that handy "export" keyword and the dot-feature (. command) - save for a few carefully selected exceptions. If a function needs a certain value from another function calling it, it has to be in the parameters. This way - usually even before i write that function - i have its "interface": which parameters it needs, which return values it produces, which output it creates - already laid out.
So, to sum it up: if you have thousands of lines of code and cannot keep track of your variables i suppose you should do a major code review and rewrite the parts where you needed a variable-tracker in the first place. After some serious restructuring of the code the need for such tools might just go away.
I hope this helps (ahh well, see above).
bakunin
These 2 Users Gave Thanks to bakunin For This Post:
Hi all...
(Apologies for the delay but I have had other commitments. Also for any typos.)
@bakunin...
(Have you tried the code out at all to see what it does?)
1) I am not a software engineer, but a retired, mere amateur. ;o)
2) This project was for me to learn shell scripting, of which I know much more now than day one.
3) There are many functions inside the program that can't really be made simpler than they are and there are also some simple ones called regularly.
4) There are a lot of variables and all are used, there are no extras that have been found. I like _bash_'s flexibiilty and things that It, along with the Terminal, can do makes life interesting. Along the way I have discovered some strange effects of the hardware that I and I suspect nearly everyone else did not know.
5) Lastly a rewrite of the code would be difficult as it has evolved to become a tool that even I could not have imagined - back at the start of this project I bragged about doing this but never in my wildest dreams did I expect it to get where it is. It HAS had a write up in Linux Format Magazine and this is a shock to the system to say the least.
6) Fimally this script does everything EXCEPT build the external hardware for you...
A) Although unfinished, contains the circuits; so far.
B) Generates ALL necessary files plus have extras that you can use elsewhere as .WAV files.
C) Creates a working Audio Oscilloscope using text mode inside a terminal without the need for fancy graphics.
D) Uses 3 dedicated capture modes, along with 3 other modes that are platform specific.
E) Uses ONLY the mic/ear socket of an MBP 13 inch OSX 10.7.5 using the default bash terminal.
F) It has evolved over time.
G) And LBNL, I don't think this has ever been attempted anywhere elsebefore.
H) Capable of doing both AC and DC measurements to a minimum of 4 - 5 bit depth.
I) Other things that elude me at the moment.
It is designed to run on hopefully UNIX, definitely various Linux flavours in both 32 and 64 bit guises, CygWin and CygWin64 and MBP/iMac OSX 10.7.x minimum.
So to finalise, you have not annoyed me but it would be very difficult to start again with my current knowledge so I am coding this in its original coding style.
A listing of the files generated for the current version:-
@Corona688...
OK, maybe backwards compatibilty is not the phrase to use, however I do test on various platforms. Several Linux flavours using live DVDs, iMac and MBP, CygWin and CygWin64 of which the latter did show up a bug NOT even related to printf . I have even used the 'printf' inside /usr/bin/printf which does NOT allow escaped hex values but only octal ones but decided that the hex ones looked neater.
I would like professional opinions on trying it out in their UNIX flavours however, even if you don't like it.
And finally the variables are all used and none are detected as not being allocated during program run.
I hope this clears it up and the next upload will be the AC condition finalised with builds and calibration of the AC vertical axis.
The DC conditions will be much harder, Arduino and the first home built 'ALTDC' are done and coded for but not calibrated yet.
Dear all,
I have a new Oracle Blade X4-2B server, running Solaris 10.
The server comes with a HBA card that will not be used now. It has not fibers connected to it. As a consequence, its leds never stop flashing.
My question is: how to disable this HBA card, without removing it physically... (2 Replies)
Hello,
When creating shared memory in C, should be remove shared memory with shmctl function when don't need it. If it didn't remove, occupied shared memory stay and remain.
If we create shared memory repeatedly without removing unusable shared memory, /dev/shm will full.
Does Unix or... (1 Reply)
Hi,
In our AIX 5.2 server , we have one unused ethernet adapter which doesn't have cable connection . For this interface , we are getting alerts in errpt .
Could you suggesthow to stop this alert ? And sametime i would like to keep this device in ODM .
Is there... (1 Reply)
i Have alloted 20G in my vmware for solaris 10, upon installation, and some distribution of disk space to /,/opt,swap i just use 19G.
Can i still use the 1G? How? how to see the 1G? that i did not use? how can i use it?
appreciate your responce (17 Replies)
Hello,
I have a system with HP-UX 11.23 installed on it. There are ~36GB of unused space on the HDD. I did a very basic installation, and it created the usual volume group /dev/vg00. When I look at the output of ioscan -funC disk, I see this (and more, but irrelevant to this post):
disk ... (1 Reply)
Hi,
How do I query for unused partition in AIX 4.3 with DAS and SAA storage?
I know most unix administrator don't put all the capacity on the system at once.
thanks,
vene (1 Reply)
One of my Solaris 8 machines hd was about to die. So I used g4u to create an image of the 9gb drive and I put it in a 36gb drive. That solved my dieing hd problem.
But....
How do I get my machine to see the unused 27gb of space?
Any help would be greatly appreciated. (1 Reply)