Layers of Layers
Have you tried adding an abstraction layer?
  • Cheat Sheets
    • Linux Commands
    • Linux Network
    • Markdown
    • Regular Expressions
    • Shell Scripting
    • SSL
    • VI
  • To Do
    • Blinkendecke
    • DIY Electronics Construction Kit from Duplo
    • Kobo Hacking
  • $FOO
  • Linux
  • Make
  • misc
  • Pretty
  • Software
  • Things

Shell Scripting

  • Shebang
    • Portable Shebang
  • Test
    • Boolean Test
    • File tests
    • String tests
    • Arithmetic tests
    • Misc syntax
  • Directory
    • There and Back Again
  • Output

Shebang

Portable Shebang

Its not as simple as it looks
#!/usr/bin/env sh

Test

Boolean Test

IT_HAS_IPMI=true
[ "$IT_HAS_IPMI" = true ]

File tests

This section probably holds the most tests, I'll list them in some logical order. Since Bash 4.1, all tests related to permissions respect ACLs, if the underlying filesystem/OS supports them.

Operator syntax Description
-a True if exists. :!: (not recommended, may collide with ''-a'' for ''AND'', see below)
-e True if exists.
-f True, if exists and is a regular file.
-d True, if exists and is a directory.
-c True, if exists and is a character special file.
-b True, if exists and is a block special file.
-p True, if exists and is a named pipe (FIFO).
-S True, if exists and is a socket file.
-L True, if exists and is a symbolic link.
-h True, if exists and is a symbolic link.
-g True, if exists and has sgid bit set.
-u True, if exists and has suid bit set.
-r True, if exists and is readable.
-w True, if exists and is writable.
-x True, if exists and is executable.
-s True, if exists and has size bigger than 0 (not empty).
-t True, if file descriptor is open and refers to a terminal.
-nt True, if is newer than (mtime). :!:
-ot True, if is older than (mtime). :!:
-ef True, if is a hardlink to . :!:

String tests

Operator syntax Description
-z True, if is empty.
-n True, if is not empty (this is the default operation).
= True, if the strings are equal.
!= True, if the strings are not equal.
< True if sorts before lexicographically (pure ASCII, not current locale!). Remember to escape! Use ''\<''
> True if sorts after lexicographically (pure ASCII, not current locale!). Remember to escape! Use ''>''

Arithmetic tests

Operator syntax Description
-eq True, if the integers are equal.
-ne True, if the integers are NOT equal.
-le True, if the first integer is less than or equal second one.
-ge True, if the first integer is greater than or equal second one.
-lt True, if the first integer is less than second one.
-gt True, if the first integer is greater than second one.

Misc syntax

Operator syntax Description
-a True, if and are true (AND). Note that ''-a'' also may be used as a file test (see above)
-o True, if either or is true (OR).
! True, if is false (NOT).
( ) Group a test (for precedence). Attention: In normal shell-usage, the "(" and ")" must be escaped; use "(" and ")"!
-o True, if the [[internals:shell_options
-v True if the variable has been set (since 4.2-alpha). Can't be used to determine if an array index is set, only array names.
-R True if the variable has been set and is a nameref variable (since 4.3-alpha)

Directory

There and Back Again

Command Description
pushd /somewhere going away
*popd coming back

Output

echo -n "blah\nblah\tblah"

Tags

  • Graphics
  • bash
  • Javascript
  • Database
  • Powersave
  • Cyanogen
  • synology
  • Ideas
  • Android
  • Security
  • Internal
  • Blog
  • Books
  • Network
  • Wood
  • Wallpapers
  • RasPi
  • Storage
  • Serious
  • KDE
  • Cookies
  • Suse
  • Themes
  • Ubuntu
  • Kids
  • Photos
  • Hardware
  • Java
  • Git
  • Pelican
  • Games
  • Virtualization
  • Eclipse

Links

  • CCC-FFM
  • Cat Content
design by jide