-2

I am trying to create a script that takes a parameter with a / in the between the directory and file. I then want to create the directory and create the file inside that directory. I don't really have a huge idea of what I am doing so I don't have any code other than the basic skeleton for a bash if statement.

#!/bin/bash

if [ $1 ?? "/" ]; then
   do
fi

If for example the parameter of Website/Google is passed a directory called Website should be created with a file called Google inside it.

Ronan Byrne
  • 237
  • 2
  • 3
  • 9
  • 1
    Possible duplicate of [How to check if a string contains a substring in Bash](https://stackoverflow.com/q/229551/608639), [Check if string containts slash or backslash in Bash?](https://stackoverflow.com/q/18148883/608639), [How to check the first character in a string in Bash or UNIX shell?](https://stackoverflow.com/q/18488270/608639), etc. – jww Nov 01 '19 at 16:23

1 Answers1

0
if [[ "$1" = */* ]];
  dir=${1#/*}
  file=${1%%*/}
fi

in bash, or more generally for a POSIX-compatible shell,

case $1 in
  */*) dir=${1#/*}; file=${1%%*/} ;;
esac
chepner
  • 497,756
  • 71
  • 530
  • 681