Skip to content

Latest commit

 

History

History
85 lines (58 loc) · 2.56 KB

scratch.adoc

File metadata and controls

85 lines (58 loc) · 2.56 KB

for fake-nic.sh:

#!/bin/bash

if [ "$(id -u)" != "0" ]; then
  echo "This script must be run as root"
  exit 1
fi

echo -n "Enter new username: "; read user
echo -n "Enter new password: "; read pass

printf "$user:$(openssl passwd -crypt $pass)\n" >> /etc/nginx/.htpasswd
$ echo 'NET "ddr3_dq0" LOC = "AY12" | IOSTANDARD = SSTL15_T_DCI | VCCAUX_IO = NORMAL | SLEW = FAST;' | sed '/^$/d;s/[\"=|;]//g;s/[\t]*//g;s/\ \{1,\}/\ /g' | sed 's/NET[ ]*\([_a-zA-Z0-9]*\)[ ]*LOC[ ]*\([A-Z0-9]*\)[ ]*IOSTANDARD[ ]*\([_A-Z0-9]*\)[ ]*VCCAUX_IO[ ]*\([A-Z]*\)[ ]*SLEW[ ]*\([A-Z]*\)/\1 \2 \3 \4 \5/g'
$ echo 'NET "ddr3_dq[0]" LOC = "AY12" | IOSTANDARD = SSTL15_T_DCI | VCCAUX_IO = NORMAL | SLEW = FAST;' | sed '/^$/d;s/[\"=|;]//g;s/[\t]*//g;s/\ \{1,\}/\ /g'
NET ddr3_dq[0] LOC AY12 IOSTANDARD SSTL15_T_DCI VCCAUX_IO NORMAL SLEW FAST

replace several whitespace by one: $ sed 's/\ \{1,\}/\ /g'

remove blank string from file: $ sed '/^$/d' input.txt > output.txt

[ "$x" == "valid" ] && echo "valid" || echo "invalid"
sed ':a;N;$!ba;s/\n/<text>/g'

where:

  • :a - create a label 'a'

  • N - append the next line to the pattern space

  • $! - if not the last line

  • ba - branch (go to) label 'a'

  • s - substitute

  • /\n/ - regex for new line

  • /<text>/ - with text "<text>"

  • g - global match (as many times as it can)

how to check if $1 and $2 are null?

Try using the -z test: if [ -z "$1" ] && [ -z "$2" ]

From man bash: -z string True if the length of string is zero.

```
if [ "$#" -ne 1 ]; then
    echo "Illegal number of parameters"
fi
```

Or

```
if test "$#" -ne 1; then
    echo "Illegal number of parameters"
fi
```


---------------

* http://askubuntu.com/questions/444082/how-to-check-if-1-and-2-are-null[how to check if $1 and $2 are null?]
* http://stackoverflow.com/questions/18568706/checking-number-of-arguments-bash-script[checking number of arguments bash script]
* http://stackoverflow.com/questions/6482377/check-existence-of-input-argument-in-a-bash-shell-script[Check existence of input argument in a Bash shell script]

* http://linuxcommand.org/wss0100.php[Writing shell scripts - Lesson 10: Stay Out Of Trouble]
* http://stackoverflow.com/questions/2237080/how-to-compare-strings-in-bash-script
* http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression
* http://tldp.org/LDP/abs/html/comparison-ops.html
* http://tldp.org/LDP/abs/html/loops1.html
* http://ryanstutorials.net/bash-scripting-tutorial/bash-loops.php
* http://www.canbike.org/information-technology/sed-delete-carriage-returns-and-linefeeds-crlf.html