0

Hi I'm trying to get my script to continue If enter is hit or to take the input as a variable my code is:

echo " hit enter for default directory or insert a new directory"
read var
if
[ var = *enter* ]
then 
echo "enter pressed"
else
echo $var
fi 

Please use enter as me not knowing what comes next

JONAS402
  • 591
  • 1
  • 9
  • 18
  • possible duplicate of [Bash Shell Scripting - return key/Enter key](http://stackoverflow.com/questions/2612274/bash-shell-scripting-return-key-enter-key) – Etan Reisner Apr 22 '15 at 14:27

1 Answers1

1

This script prints "Default directory" if ENTER is pressed, and the name of the new directory if anything else is entered:

#!/bin/bash

echo "Hit enter for default directory or insert a new directory"
read var

if [[ $var = "" ]]; then
    echo "Default directory"
else
    echo "New directory: $var"
fi
S Anand
  • 11,364
  • 2
  • 28
  • 23
  • This what I am after thanks alot, I can see how my question could be seen as duplicate – JONAS402 Apr 22 '15 at 14:42
  • Yes, it was quite similar to [Bash Shell Scripting - return key/Enter key](http://stackoverflow.com/questions/2612274/bash-shell-scripting-return-key-enter-key). But you're trying to actually read a value, not just detect Enter. So that makes it (and the solution) a bit different. – S Anand Apr 22 '15 at 14:43