Search Results

Search: Posts Made By: cfajohnson
18,313
Posted By cfajohnson
array_save() { eval "printf '%s\n'...
array_save()
{
eval "printf '%s\n' \"\${${x}[@]}\""
} > "${2:-/dev/tty}"
27,327
Posted By cfajohnson
Top Ten Reasons not to use the C shell...
Top Ten Reasons not to use the C shell (http://www.grymoire.com/Unix/CshTop10.txt) Csh problems (http://www.grymoire.com/Unix/Csh.html#uh-0) Csh Programming Considered Harmful...
7,316
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 <<<...
22,907
Posted By cfajohnson
I'd simplify the whole thing by shuffling the...
I'd simplify the whole thing by shuffling the deck and then dealing from it.

There are 3 functions in this snippet:
shuffle, which shuffles a standard deck of cards into a space-separated string...
3,190
Posted By cfajohnson
"$*" and "$@" are not exit codes; they are the...
"$*" and "$@" are not exit codes; they are the command line arguments.

Exit codes are stored in "$?".

When unquoted, $* and $@ are the same; each word in the argument list becomes a separate...
3,197
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...
9,015
Posted By cfajohnson
s/crippled/standard/
s/crippled/standard/
9,015
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,202
Posted By cfajohnson
That will fail if $AllFile contains whitespace. ...
That will fail if $AllFile contains whitespace.

}' "$AllFile.tmp" > "$AllFile"
5,030
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....
5,030
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.
2,308
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}"
Forum: What is on Your Mind? 06-04-2015
1,714
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.
3,327
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...
8,106
Posted By cfajohnson
for f in * do [ -s "$f" ] && continue ##...
for f in *
do
[ -s "$f" ] && continue ## file exists, but is not empty
[ -f "$f" ] && rm "$f"
done
3,741
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,661
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."
3,741
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 ))
95,905
Posted By cfajohnson
set -f IFS=' ' set -- $( cat list2 ) for...
set -f
IFS='
'
set -- $( cat list2 )
for i in `cat list1`
do
printf "%s %s\n" "$i" "$1"
shift
done
7,715
Posted By cfajohnson
Put this in a script or a function: n=200...
Put this in a script or a function:


n=200 ## adjust to taste: higher value, lighter background
n1=$(( 256 - $n ))
bg=$( printf "#%x%x%x\n" $(( $RANDOM % $n1 + $n )) \
...
1,144
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,978
Posted By cfajohnson
grep "^$acc;" "$file"
grep "^$acc;" "$file"
6,659
Posted By cfajohnson
There's no point in sourcing the script if you...
There's no point in sourcing the script if you are putting it in the background.

A background process is not executed in the current shell.
1,828
Posted By cfajohnson
tab=$'\t' read num grep "^$num$tab" | cut...
tab=$'\t'
read num
grep "^$num$tab" | cut -f2-
4,109
Posted By cfajohnson
There should be no space after file, and you...
There should be no space after file, and you don't need both $( ... ) and ` ... `.

date=$(date +%Y%m%d)
file=$(find . -name "$date"_*.xml)
mv "$file" renamedfeed_"$date".xml
Showing results 1 to 25 of 117

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