Search Results

Search: Posts Made By: cfajohnson
3,044
Posted By cfajohnson
Where do you think tr is getting its input?
Where do you think tr is getting its input?
8,256
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 <<<...
11,039
Posted By cfajohnson
s/crippled/standard/
s/crippled/standard/
1,683
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.
1,611
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 ((...
11,039
Posted By cfajohnson
Indeed. Fixed.
Indeed. Fixed.
4,049
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...
11,039
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...
3,941
Posted By cfajohnson
That will fail if $AllFile contains whitespace. ...
That will fail if $AllFile contains whitespace.

}' "$AllFile.tmp" > "$AllFile"
6,269
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.
6,269
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....
3,014
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}"
2,145
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##*/}
3,898
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
2,917
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.
4,021
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...
3,181
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."
4,878
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).
4,878
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:
...
2,396
Posted By cfajohnson
UUOC tr -d '\0' < file
UUOC

tr -d '\0' < file
4,878
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 ))
2,646
Posted By cfajohnson
Try quoting $line: vmd.sh -dispdev text...
Try quoting $line:


vmd.sh -dispdev text -e vmdgenpqr.tcl -args "$line"
2,282
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}"...
1,531
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 "
...
2,711
Posted By cfajohnson
grep "^$acc;" "$file"
grep "^$acc;" "$file"
Showing results 1 to 25 of 500

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