Difference between revisions of "Bash"
From Leaky
(Created page with ' == Find the location of a script, no matter how it's referenced when run == DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo $DIR') |
(→Convert files/text to hex and back) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | |||
== Find the location of a script, no matter how it's referenced when run == | == Find the location of a script, no matter how it's referenced when run == | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
echo $DIR | echo $DIR | ||
+ | |||
+ | == Convert files/text to hex and back == | ||
+ | |||
+ | I had a weird looking filename in a backup and found the following while trying to figure out what the character might be. | ||
+ | |||
+ | [user@host photos]$ ls | xxd -g1 | ||
+ | 0000000: ef 80 a3 33 2e 70 6e 67 0a ...3.png. | ||
+ | [user@host photos]$ xxd -g1 -r | ||
+ | 0000000: ef 80 a3 33 2e 70 6e 67 0a ...3.png. | ||
+ | 3.png | ||
+ | |||
+ | xxd is part of vim-common on CentOS and it's better than od because -r will reverse the hex dump and convert it to a binary file! | ||
+ | |||
+ | == replace file extensions without sed == | ||
+ | |||
+ | for i in *.sh; do echo "${i%.sh}.bat"; done |
Latest revision as of 11:09, 14 July 2015
Find the location of a script, no matter how it's referenced when run
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo $DIR
Convert files/text to hex and back
I had a weird looking filename in a backup and found the following while trying to figure out what the character might be.
[user@host photos]$ ls | xxd -g1 0000000: ef 80 a3 33 2e 70 6e 67 0a ...3.png. [user@host photos]$ xxd -g1 -r 0000000: ef 80 a3 33 2e 70 6e 67 0a ...3.png. 3.png
xxd is part of vim-common on CentOS and it's better than od because -r will reverse the hex dump and convert it to a binary file!
replace file extensions without sed
for i in *.sh; do echo "${i%.sh}.bat"; done