Skip to content

Instantly share code, notes, and snippets.

@mattintosh4
Last active August 29, 2015 14:23
Show Gist options
  • Save mattintosh4/779ba8d8defeed929291 to your computer and use it in GitHub Desktop.
Save mattintosh4/779ba8d8defeed929291 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Hello, World!"
echo -n "do not output the trailing newline"
echo -e "enable interpretation of backslash escapes"
echo -E "disable interpretation of backslash escapes (default)"
$ chmod +x ~/sample.sh
$ stat ~/sample.sh
File: ‘/home/matthew/sample.sh’
Size: 268 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 31484938 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 1000/ matthew) Gid: ( 1000/ matthew)
Access: 2015-06-20 12:12:29.612627167 +0900
Modify: 2015-06-20 11:50:28.417328297 +0900
Change: 2015-06-20 11:50:28.447328167 +0900
Birth: -
$ ~/sample.sh
Hello, World!
do not output the trailing newlineenable interpretation of backslash escapes
disable interpretation of backslash escapes (default)
#!/bin/bash
### SYNOPSIS ###
# echo [SHORT-OPTION]... [STRING]...
# echo LONG-OPTION
PS4=$'\e[41;5m>>>\e[m '
set -x
echo "Hello, World!"
echo -n "do not output the trailing newline"
echo -e "enable interpretation of backslash escapes"
echo -E "disable interpretation of backslash escapes (default)"
echo --help
echo --version
/bin/echo --help
/bin/echo --version
--- /dev/fd/13 2015-06-21 19:30:00.000000000 +0900
+++ /dev/fd/14 2015-06-21 19:30:00.000000000 +0900
@@ -1,6 +1,17 @@
#!/bin/bash
+### SYNOPSIS ###
+# echo [SHORT-OPTION]... [STRING]...
+# echo LONG-OPTION
+
+PS4=$'\e[41;5m>>>\e[m '
+set -x
+
echo "Hello, World!"
echo -n "do not output the trailing newline"
echo -e "enable interpretation of backslash escapes"
echo -E "disable interpretation of backslash escapes (default)"
+echo --help
+echo --version
+/bin/echo --help
+/bin/echo --version
$ ~/sample.sh
>>> echo 'Hello, World!'
Hello, World!
>>> echo -n 'do not output the trailing newline'
do not output the trailing newline>>> echo -e 'enable interpretation of backslash escapes'
enable interpretation of backslash escapes
>>> echo -E 'disable interpretation of backslash escapes (default)'
disable interpretation of backslash escapes (default)
>>> echo --help
--help
>>> echo --version
--version
>>> /bin/echo --help
Usage: /bin/echo [SHORT-OPTION]... [STRING]...
or: /bin/echo LONG-OPTION
Echo the STRING(s) to standard output.
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes (default)
--help display this help and exit
--version output version information and exit
If -e is in effect, the following sequences are recognized:
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\0NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)
NOTE: your shell may have its own version of echo, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
For complete documentation, run: info coreutils 'echo invocation'
>>> /bin/echo --version
echo (GNU coreutils) 8.23
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Brian Fox and Chet Ramey.
#!/bin/bash -x
echo "xtrace が ON です"
echo "xtrace を OFF にします"
set +x
echo "xtrace は OFF です"
echo "xtrace を ON にします"
set -o xtrace
echo "xtrace は ON です"
echo "xtrace を OFF にします"
set +o xtrace
echo "xtrace は OFF です"
+ echo 'xtrace が ON です'
xtrace が ON です
+ echo 'xtrace を OFF にします'
xtrace を OFF にします
+ set +x
xtrace は OFF です
xtrace を ON にします
+ echo 'xtrace は ON です'
xtrace は ON です
+ echo 'xtrace を OFF にします'
xtrace を OFF にします
+ set +o xtrace
xtrace は OFF です
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment