sudo echo “something” >> /etc/privilegedFile doesn’t work [duplicate]

Use tee –append or tee -a. echo ‘deb blah … blah’ | sudo tee -a /etc/apt/sources.list Make sure to avoid quotes inside quotes. To avoid printing data back to the console, redirect the output to /dev/null. echo ‘deb blah … blah’ | sudo tee -a /etc/apt/sources.list > /dev/null Remember about the (-a/–append) flag! Just tee … Read more

How do I know the script file name in a Bash script?

me=`basename “$0″` For reading through a symlink1, which is usually not what you want (you usually don’t want to confuse the user this way), try: me=”$(basename “$(test -L “$0” && readlink “$0” || echo “$0″)”)” IMO, that’ll produce confusing output. “I ran foo.sh, but it’s saying I’m running bar.sh!? Must be a bug!” Besides, one … Read more

How do I compare two string variables in an ‘if’ statement in Bash? [duplicate]

For string equality comparison, use: if [[ “$s1” == “$s2” ]] For string does NOT equal comparison, use: if [[ “$s1” != “$s2” ]] For the a contains b, use: if [[ $s1 == *”$s2″* ]] (and make sure to add spaces between the symbols): Bad: if [[“$s1” == “$s2”]] Good: if [[ “$s1” == … Read more

How does “cat

The cat <<EOF syntax is very useful when working with multi-line text in Bash, eg. when assigning multi-line string to a shell variable, file or a pipe. Examples of cat <<EOF syntax usage in Bash: 1. Assign multi-line string to a shell variable $ sql=$(cat <<EOF SELECT foo, bar FROM db WHERE foo=’baz’ EOF ) … Read more

How to run a PowerShell script

Prerequisites: You need to be able to run PowerShell as an administrator You need to set your PowerShell execution policy to a permissive value or be able to bypass it Steps: Launch Windows PowerShell as an Administrator, and wait for the PS> prompt to appear Navigate within PowerShell to the directory where the script lives: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)