Visit The New, Modern Unix Linux Community

Search Results

Search: Posts Made By: cfajohnson
1,116
Posted By cfajohnson
Where do you think tr is getting its input?
Where do you think tr is getting its input?
3,134
Posted By cfajohnson
If you have the output in a variable, you don't...
If you have the output in a variable, you don't need any external command:

output='Device "nrst3a" attributes=(0x4) RAW SERIAL_NUMBER=SN[VD073AV1443BVW00083]L2'

IFS=\" read a s1 b <<<...
4,859
Posted By cfajohnson
s/crippled/standard/
s/crippled/standard/
853
Posted By cfajohnson
Better would be: find . -size +1073741823c...
Better would be:

find . -size +1073741823c -exec ls -l {} +

Besides using many fewer calls to ls, the listings will be properly aligned.
840
Posted By cfajohnson
The second example is missing an fi; you have 2...
The second example is missing an fi; you have 2 ifs, but only one fi. Better is, as Scrutinizer pointed out, to use elif ...; then.

In bash, you can use:

if (( num < pmin )); then


if ((...
4,859
Posted By cfajohnson
Indeed. Fixed.
Indeed. Fixed.
1,895
Posted By cfajohnson
awk 'BEGIN { print "<div align=center>" } {...
awk 'BEGIN { print "<div align=center>" }
{ gsub(/&/,"&amp;"); gsub(/</,"&lt;") }
/^$/ { print; last = "blank"; next }
last == "blank" || NR == 1 {
last = ""
printf " <p>"
}
/THE DISTRICT COURT...
4,859
Posted By cfajohnson
That will only work with the GNU date command; -d...
That will only work with the GNU date command; -d is not standard.



I doubt that OP is using a system without a POSIX shell, so there's no need for cut:

IFS=/ read month day year whatever...
2,008
Posted By cfajohnson
That will fail if $AllFile contains whitespace. ...
That will fail if $AllFile contains whitespace.

}' "$AllFile.tmp" > "$AllFile"
1,980
Posted By cfajohnson
Do not use basename. It is an external command...
Do not use basename. It is an external command that is an order of magnitude slower than using the shell's parameter expansion.
1,980
Posted By cfajohnson
That is almost almost always the wrong way ro...
That is almost almost always the wrong way ro read the contents of a file. Not only is cat unnecssary but it will break your script if any lines contain whitespace or other pathological characters....
1,145
Posted By cfajohnson
With bash there is no need for any external...
With bash there is no need for any external command:


#!/bin/bash
file=$1

mapfile -t xx < "$file"
n=${#xx[@]}
printf "%s\n" "${xx[@]:1:n-2}"
1,301
Posted By cfajohnson
Probably my most frequent use is to get the...
Probably my most frequent use is to get the filename from a full path, essentally replacing the basename command:


path=/path/to/file
file=${path##*/}
1,274
Posted By cfajohnson
You probably want a while loop rather than an...
You probably want a while loop rather than an until loop:


while [[ $# -ne 0 ]]
do
echo "\$# = " $#
echo "$1"
shift
done


It can also be written: while (($#))

Or:

until (( $#...
Forum: What is on Your Mind? 06-04-2015
1,086
Posted By cfajohnson
The best places I have found are this forum and...
The best places I have found are this forum and the Usenet newsgroup comp.unix.shell.
1,387
Posted By cfajohnson
First, you don't need -1 when the output of ls is...
First, you don't need -1 when the output of ls is not going to a terminal.

Second, the command will fail if $1 contains whitespace or other pathological characters.

Third, there is no need for...
1,656
Posted By cfajohnson
man bash:"Redirections using file descriptors...
man bash:"Redirections using file descriptors greater than 9 should be used with care, as they may conflict with file descriptors the shell uses internally."
1,758
Posted By cfajohnson
The only difference is that [ requires a closing...
The only difference is that [ requires a closing ].

AMIGA:barrywalker~> if test "$var" == "Bazza..."; then echo "$var"; fi

Also note that test/[ uses = not == (though bash and ksh accept it).
1,758
Posted By cfajohnson
Rather than whereis, use type; It tells you what...
Rather than whereis, use type; It tells you what the shell will actually use:


$ type [
[ is a shell builtin


With the -a option, it gives all the possible commands that could be executed:
...
1,021
Posted By cfajohnson
UUOC tr -d '\0' < file
UUOC

tr -d '\0' < file
1,758
Posted By cfajohnson
There is no need to use an external command for...
There is no need to use an external command for integer arithmetic in bash (or any other POSIX shell):

count=$(( count + 1 ))


Or, in bash:


(( ++count ))
1,832
Posted By cfajohnson
Try quoting $line: vmd.sh -dispdev text...
Try quoting $line:


vmd.sh -dispdev text -e vmdgenpqr.tcl -args "$line"
1,007
Posted By cfajohnson
If your file only has one line, you don't need...
If your file only has one line, you don't need any external commands:

read line < file

Then use parameter expansion to get the characters you want:


# bash
printf "%s%s\n" "${line:4:2}"...
761
Posted By cfajohnson
If you want to get a value from the command line,...
If you want to get a value from the command line, use the positional parameters, $1, etc., not 'read'.


case $1 in
1|memory) echo " you've selected check memory..1 sec pls "
...
1,275
Posted By cfajohnson
grep "^$acc;" "$file"
grep "^$acc;" "$file"
Showing results 1 to 25 of 500

 

Featured Tech Videos

All times are GMT -4. The time now is 03:04 AM.
Unix & Linux Forums Content Copyright 1993-2020. All Rights Reserved.
Privacy Policy