Sponsored Content
Top Forums UNIX for Advanced & Expert Users Detecting unused variables... Post 302975399 by Don Cragun on Sunday 12th of June 2016 05:39:06 AM
Old 06-12-2016
Quote:
Originally Posted by wisecracker
Thank you Don...

Your explanation is thorough and finding this sort of information on the WWW is near impossible.

It looks lke I will have to go through the AudioScope code again and clean up. There are only a few lines that contain variables to be expanded.
(BTW I meant to quote line 7 and line 18 - NOT 5. Humble apologies...)
Code:
I still don't quite understand why ShellCheck rejects:-
printf "%b" "\x1B["$y";"$x"fWorks but is not POSIX or sh compliant...\n"
But accepts:-
printf "%b" "\x1B["$y';'$x"fWorks but is POSIX and sh compliant...\n"

The only difference is ";" and ';' .
I will make the wild assumption that ShellCheck is just checking the printf utility format string operand (and perhaps checking that there are enough operands supplied to match %format-specifier and * in %*.*format-specifier occurrences in the format string operand). Since a format string can be reused if more operands are present than format specifiers, it would be a lot harder for it to determine when an unquoted shell variable is expanded in an operand is wrong versus when an unquoted shell variable in a format string could cause early termination of the format string.
Quote:
I would probably never have found this as 'x' and 'y' will always be integers.
Once again you have put me on the straight and narrow.
Finally, do I assume that the line below is not a valid posix 'printf' statement as it is lacking the '%b'?
Code:
 printf "\x1B[0;34;43mIs this a valid posix compliant line?"

It does work in 'sh' on this MBP, OSX 10.7.5 default terminal running sh.
(It seems '%b' is a default modifier for 'printf'.)
Finally thanks again...
No. There is nothing wrong with this this printf command (other than the fact that it won't do what you want on a machine using an EBCDIC codeset and will only work on certain output devices that understand the escape sequence you have encoded at the start of that output). There are no variables in that format string that could be expanded to require additional operands. That command (with double-quotes as you used them or with the double-quotes replaced by single-quotes) produces a partial line of output that is perfectly well-formed. And, since that format string operand contains no percent sign characters, the following commands would also be valid commands producing exactly the same output (more slowly):
Code:
printf '%s' '\x1B[0;34;43mIs this a valid posix compliant line?'
printf '%s' '\x1B[0;34;43mIs this a valid posix compliant line?'

(and, in both of those commands the 1st two single-quotes can be changed to double-quotes and the last two single-quotes can be changed to double-quotes with no difference in the output (but it will run slightly more slowly)).

Last edited by Don Cragun; 06-12-2016 at 06:47 AM.. Reason: PS removed; it wasn't in the standards even though it would work on some systems.
This User Gave Thanks to Don Cragun For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I get the unused space?

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)
Discussion started by: Spyzic
1 Replies

2. AIX

unused storage on AIX 4.3

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)
Discussion started by: venerayan
1 Replies

3. UNIX for Dummies Questions & Answers

delete the unused file

Hi All, Can you please let me know how to delete any files that have not been accessed in the past 28 days in a directory. Thanks, Arun (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

4. AIX

how to clean Unused semaphore??

How can i clean up my unused semaphore??? (4 Replies)
Discussion started by: abhishek27
4 Replies

5. HP-UX

HP-UX using unused HDD space

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)
Discussion started by: goon12
1 Replies

6. Solaris

unused disk space

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)
Discussion started by: kenshinhimura
17 Replies

7. AIX

Temporarily disabling unused ethernet adapter

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)
Discussion started by: sekarsamy
1 Replies

8. Programming

What Unix do with unused shared memory?

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)
Discussion started by: pronetin
1 Replies

9. Solaris

Solaris 10: how to disable an unused HBA card

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)
Discussion started by: Gus1971
2 Replies
All times are GMT -4. The time now is 03:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy