Sponsored Content
Top Forums UNIX for Advanced & Expert Users Detecting unused variables... Post 302973097 by drl on Saturday 14th of May 2016 07:29:14 AM
Old 05-14-2016
Hi.

Found in Debian repository (noted by Is there a static analysis tool like Lint or Perl::Critic for shell scripts? - Stack Overflow ):
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate static shell checking.
# If not in repository, see:
# http://hackage.haskell.org/package/ShellCheck
# ( Verified 2016.05.14 )

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C shellcheck

FILE=${1-data1}

pl " Input data file $FILE:"
cat $FILE

pl " Results:"
shellcheck $FILE

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.4 (jessie) 
bash GNU bash 4.3.30
ShellCheck - shell script analysis tool

-----
 Input data file data1:
#!/bin/bash

# @(#) example1.sh      Demonstrate catching of errors.

v0=7

for i in 1 2 3
do
  (( l=j+1 ))
  printf " Hello, world (from script)"
done

if [ $v1 ]
then
  echo ' My fault'
fi

exit $n

-----
 Results:

In data1 line 5:
v0=7
^-- SC2034: v0 appears unused. Verify it or export it.


In data1 line 7:
for i in 1 2 3
^-- SC2034: i appears unused. Verify it or export it.


In data1 line 13:
if [ $v1 ]
     ^-- SC2086: Double quote to prevent globbing and word splitting.


In data1 line 18:
exit $n
     ^-- SC2086: Double quote to prevent globbing and word splitting.

Best wishes ... cheers, drl
These 4 Users Gave Thanks to drl 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
MINCINFO(1)							 MINC User's Guide						       MINCINFO(1)

NAME
mincinfo - print out specified information about a minc file SYNOPSIS
mincinfo [<options>] <file> [<file> ...] DESCRIPTION
mincinfo will print out either a general description of a minc file (type, sign and range of data, plus a brief description of dimensions and their order), or specific information about dimensions, variables or attributes in the file. This program can be very useful for build- ing shell scripts that access minc files. All information given by mincinfo is presented as read from the file with no transformation. This means that start and step values, for example, are not in the world coordinate system. To display the start values for a file in world coordinates, use voxeltoworld. OPTIONS
Note that options can be specified in abbreviated form (as long as they are unique) and can be given anywhere on the command line. Dimen- sions, variables and attributes are all specified by name. Attributes are specified by variable:attribute where variable can be omitted to specify global attributes. More than one option can be specified, in which case the return value from each option is printed on a separate line (-image_info prints on many lines) in the order of the options on the command line. -image_info Print out the default general information about the file. This information includes the type, sign and range of the pixel data, the order of the dimensions, and a list of dimensions giving name, length, start and step for each one. -dimnames Print out a space-separated list of the dimensions in the file. -varnames Print out a space-separated list of the variables in the file. -dimlength dimension Print the length of the specified dimension. -vartype variable Print the type of the variable. -vardims variable Print a space-separated list of the dimensions that subscript the variable (in C order). -varatts variable Print a space-separated list of the attribute names for the specified variable. -varvalues variable Print a newline-separated list of the values of the specified variable. -atttype variable:attribute Print out the type of the specified attribute. -attvalue variable:attribute Print out a space-separated list of the values of the specified attribute. -error_string string Specifies a string to print out if an error occurs. This will cause the program to exit with normal status. The default is to print an appropriate error message and exit with an error status. -help Print summary of command-line options and abort. -version Print the program's version number and exit. EXAMPLES
Print out standard information about a minc file. mincinfo file.mnc Print out contents of global history attribute. mincinfo file.mnc -attvalue :history Print out step value for x dimension, setting the default value to 1. mincinfo file.mnc -attvalue xspace:step -error 1 Print out the step values for x, y and z, setting the default value to 1. mincinfo file.mnc -error 1 -attvalue xspace:step -attvalue yspace:step -attvalue zspace:step Print out the names of the dimensions subscripting the image variable. mincinfo file.mnc -vardims image AUTHOR
Peter Neelin COPYRIGHTS
Copyright (C) 1993 by Peter Neelin SEE ALSO
voxeltoworld(1) $Date: 2004-05-20 21:52:08 $ MINCINFO(1)
All times are GMT -4. The time now is 08:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy