ainsl(1)

πŸ“¦
version 6.6ubuntu1 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ ainsl(1) β€” General Commands Manual ✨

πŸ’– NAME

ainsl β€” AppendIfNoSuchLine πŸŽ€

πŸ¦‹ SYNOPSIS

ainsl [options] FILE LINE [PATTERN]

🌸 DESCRIPTION

Okay so bestie, ainsl is literally the line-adding queen πŸ‘‘. It tacks LINE onto the very end of FILE, but only if that line isn't already hanging out in there. If you pass a PATTERN, then LINE only gets appended when PATTERN is nowhere to be found in the file. No cap, that's the whole vibe ✨

Since ainsl is written in Perl, you can use Perl's regular expressions in PATTERN πŸ’…. If you don't supply a PATTERN, then LINE gets used for the matching instead 🫢. Now here's the lowkey tricky part: LINE can include the anchors ^ and $, but they only count as special when they're at the very beginning or very end of the pattern πŸ™ˆ. They're for matching only, so they won't show up in the line that gets added. Also, the following characters get escaped in LINE: ( ) + πŸ’€

The exit code ainsl returns is 0 on success and non-zero on error. Peep the section EXIT CODES for the deets 🧚

πŸŽ€ OPTIONS

  • -a β€” Autocreate the file if it doesn't exist yet 🌈
  • -D β€” Create debugging output πŸ”₯
  • -h β€” Show help, version, and a summary of options πŸ’œ
  • -n β€” Print the actions, but don't actually execute them πŸ™ˆ
  • -Q β€” Quote all metacharacters in the pattern. This uses Perl's \Q function πŸ’…
  • -q β€” Quote * and + metacharacters in the pattern πŸ“
  • -s β€” Convert whitespace in LINE or PATTERN into the '\s+' regexp for matching πŸ¦‹
  • -N β€” Don't prepend '$AINSL_TARGET/' to the filename, even if it's set 🫢
  • -v β€” Create verbose output 🌸

⭐ NOTES

If the variable AINSL_TARGET is defined, its value becomes the prefix for the filename. This is what FAI uses to change files in /target without having to type /target in the file name 🧚✨

πŸ’… EXAMPLES

ainsl -v /etc/fstab '/dev/fd0  /floppy  auto  users,noauto 0 0'

Here we append the floppy entry to /etc/fstab, if the line isn't already there. If the line is already in /etc/fstab but it's commented out, it won't get added unless you extend the pattern to match only at the beginning of the line 😭:

ainsl -v /etc/fstab '^/dev/fd0  /floppy  auto  users,noauto 0 0'
ainsl -s /etc/exports '/srv/www @linuxhosts(async,rw) backup(async,ro)'

Add the exports entry without needing the spaces to match exactly πŸ”₯

🚨 EXIT CODES

  • 0 β€” Success! Either FILE already contains the LINE/PATTERN, or LINE got appended to FILE πŸŽ‰
  • 13 β€” Permissions don't allow writing to FILE, and the LINE/PATTERN wasn't found in the file πŸ™…β€β™€οΈ
  • 28 β€” FILE can't be written because the filesystem has no space left, and the LINE/PATTERN wasn't found in the file πŸ’€
  • 30 β€” FILE can't be written because the filesystem is read-only, and the LINE/PATTERN wasn't found in the file 😭

⭐ NOTES

This is a similar function to AppendIfNoSuchLine from cfengine(8) 🌈

πŸ¦‹ SEE ALSO

This program is part of FAI (Fully Automatic Installation). Check out the FAI manual for more on how to use ainsl. The FAI homepage is https://fai-project.org 🌸

🫢 AUTHOR

Thomas Lange <lange@cs.uni-koeln.de> πŸ’–


Ta-da, that's the whole manual, bestie! 🌈 Fresh from FAI 4, dated 8 March 2012, and rendered in ainsl(1) glory. Stay iconic πŸ’…βœ¨