recently moved from windows to linux and i have a script to convert from batch to bash
i'm doing ok so far (at least for the commands) but i'm stuck on a few things as i'm so used the whole batch "if THIS then GOTO that" way of doing things
for example what is the bash equivalent of these three things:
1. this one checks the folder 'c:\foobar' for files with the extension of '.foo' and '.bar' and if one is detected goes to ether :foo or :bar and runs the commands
Code:
if exist c:\foobar\*.foo goto foo
if exist c:\foobar\*.bar goto bar
goto EOF
:foo
[commands here]
goto EOF
:bar
[commands here]
goto EOF
2. this will check a variable '%~x4' in this case which is the variable %4 (a full file name with extension) but modified to only show the extension part
Code:
IF /I "%~x4"==".foo" GOTO foo
IF /I "%~x4"==".bar" GOTO bar
goto EOF
:foo
[commands here]
goto EOF
:bar
[commands here]
goto EOF
3. a bit like #2 but for folder names so it looks for the word 'foo' in the %~4 variable (a folder name)
Code:
echo "%~4" | findstr /i "foo" >nul 2>&1 && GOTO foo
echo "%~4" | findstr /i "bar" >nul 2>&1 && GOTO bar
goto EOF
:foo
[commands here]
goto EOF
:bar
[commands here]
goto EOF
would be awesome to know how to do this in bash