developer

Extract filename and extension in Bash

Question: ❓❓❓ I want to get the filename (without extension) and the extension separately. The best solution I found so far is: NAME=`echo "$FILE" | cut -d'.' -f1` EXTENSION=`echo "$FILE" | cut -d'.' -f2` This is wrong because it doesn’t work if the file name contains multiple “.” characters. If, Read more…

By admin, ago
developer

String contains in Bash

Question: ❓❓❓ Using Bash, I have a string: string = "My string" How can I test if it contains another string? if [ $string ?? 'foo' ]; then echo "It's there!" fi Where ?? is my unknown operator. Do I use echo and grep? if echo "$string" | grep 'foo'; Read more…

By admin, ago
developer

How to concatenate string variables in Bash?

Question: ❓❓❓ In PHP, strings are concatenated together as follows: $foo = "Hello"; $foo .= " World"; Here, $foo becomes “Hello World”. How is this accomplished in Bash? Good Answer: 👌👌👌 foo="Hello" foo="$foo World" echo $foo > Hello World In general to concatenate two variables you can just write them Read more…

By admin, ago