From b403584c63edd6bfb2761cadf33d1768ba22dbd5 Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Sun, 15 Nov 2020 21:58:22 +0100 Subject: [PATCH] clarify functions --- basics/bash.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/basics/bash.md b/basics/bash.md index 3124823..070e54f 100644 --- a/basics/bash.md +++ b/basics/bash.md @@ -102,9 +102,24 @@ Measure how long a script takes for super-autism powers. # Functions -> function my_funct(){ do_thing $1; } +Make a function which checks if something is a file, and if so, shows it on screen with `cat`: -Remove a function with +> function show(){ +> file "$1" | grep text &\>/dev/null && cat "$1" +> } + +That `$1` refers to the first argument typed after the command. +If you want to run this on a file called `list`, then use: + +> show list + +...and the list will output, only if it is text. + +In total, this functions the same as typing: + +> file list | grep text &\>/dev/null && list + +Remove a function with: > unset my_function