Visit Our UNIX and Linux User Community

Search Results

Search: Posts Made By: cfajohnson
4,911
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 <<<...
6,954
Posted By cfajohnson
s/crippled/standard/
s/crippled/standard/
2,353
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...
6,954
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,538
Posted By cfajohnson
That will fail if $AllFile contains whitespace. ...
That will fail if $AllFile contains whitespace.

}' "$AllFile.tmp" > "$AllFile"
2,549
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,549
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,435
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,288
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,967
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,987
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."
2,436
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,436
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 ))
876
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,578
Posted By cfajohnson
grep "^$acc;" "$file"
grep "^$acc;" "$file"
5,059
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.
2,431
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
7,069
Posted By cfajohnson
## NAME: topntail ## USAGE: topntail [-b N] [-e...
## NAME: topntail
## USAGE: topntail [-b N] [-e N] [FILE ...]

b=1 ## No. of lines to remove from beginning
e=1 ## No. of lines to remove from end

## Parse command-line options
while...
724
Posted By cfajohnson
Please convert the DOC file to a TXT file. I'm...
Please convert the DOC file to a TXT file. I'm not going to load OpenOffice just for that.
3,332
Posted By cfajohnson
Use the format specifiers to get whatever output...
Use the format specifiers to get whatever output you want. For example:

date +%y%m%d

See the man page for the full list of specifiers.
1,677
Posted By cfajohnson
awk '/^processor/ { processor = $0 } /^model...
awk '/^processor/ { processor = $0 }
/^model name/ { print processor, $0 }
' /proc/cpuinfo

I'll leave the removal of "model name :" to you.
8,141
Posted By cfajohnson
There is nothing in the script that is...
There is nothing in the script that is specifically bash other than ==; = works just as well and is portable.
3,248
Posted By cfajohnson
Put code inside [CODE] tags, not [QUOTE] tags. ...
Put code inside [CODE] tags, not [QUOTE] tags.

(You can edit your post to fix it.)
19,178
Posted By cfajohnson
#!/bin/bash usage="${0##*/} SERVER USER...
#!/bin/bash

usage="${0##*/} SERVER USER PASSWORD [PORT]"

case $1 in
-*|"") printf "USAGE: %s\n" "$usage"; exit ;;
esac

host=${1:-mail.example.com}
user=${2:-poppy}...
1,219
Posted By cfajohnson
logfile=backup_every_hour_script.log { ...
logfile=backup_every_hour_script.log
{
rsync -auv "$dir" "$backup_dir"
cat "$logfile"
} > tmpfile
mv tmpfile "$logfile"
Showing results 1 to 25 of 117

 

Featured Tech Videos

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