What is this strange syntax inside `find -exec`?

Recently I've came across a strange bash script, which is used to call a custom bash function from inside find -exec. I've developed following simple script to demonstrate the functionality I need to get explained. In the following example, function...
more »

2017-08-10 12:08 (1) Answers

find - suppress "No such file or directory" errors

I can use -s in grep to suppress errors, but I don't see an equivalent for the find command in the man page... Is the only option to redirect STDERR>/dev/null? Or is there an option that handles this? (open to fancy awk and perl solutions if needed)...
more »

2017-08-08 19:08 (1) Answers

Printing the word echo in the output of cat file

I am trying to generate a file using cat in bash where inside the bash, i already ran a script, that i saved into a variable then will be used inside the cat. To ran the script and save the output to a variable, I used the following: declare RESULT...
more »

2017-08-08 17:08 (2) Answers

EOF issue in shell script

This following code segment giving error:14: syntax error: unexpected end of file #!/bin/bash func_some() { cd some_directory lftp -u user,'password' sftp://192.168.xx.xx <<EOF cd some_directory mget ADMS_report_*${2}${3}${4}*....
more »

2017-08-08 09:08 (1) Answers

Is active waiting common in linux

I am in a debate with a colleague that it is bad programming if you do active waiting in Linux. He is more experienced than I am in bash scripting and says it is common to do it. For example, we try to start a bash script after a WiFi USB is insert...
more »

2017-08-07 17:08 (2) Answers

Conditionally execute a .bashrc command

I wanted to attach my Google Drive to my local machine (linux) so that I could access it via my terminal. After some googling, I saw that I could install google-drive-ocamlfuse to do this. When I boot my machine, I have to type: google-drive-ocaml...
more »

2017-08-05 21:08 (1) Answers

How to avoid magic-numbers in shell?

I always write some magic numbers in my interactive shells and shell scripts. For instance, If I want to list my users's names and shells, I'll write cut --delimiter=: --fields=1,7 /etc/passwd There exist two magic-numbers 1,7. And there are mor...
more »

2017-08-05 13:08 (6) Answers

Convert parts of strings to another character set

I need to display the text in the utf-8 encoding. echo "sometext1 ${DATA[1]} \ sometext2 ${DATA[2]} \ sometext3 ${DATA[3]} \ sometext4 ${DATA[4]} \ sometext5 ${DATA[5]}" sometext* text with the encoding of utf-8 ${DATA[1]} Contains digits ${DATA...
more »

2017-08-01 11:08 (1) Answers

Bash - alternative for: ls | grep

I use the following pipe as variable in a script: match=$( ls | grep -i "$search") this is then used in an if statement: if [ "$match" ]; then echo "matches found" else echo "no matches found" fi what would be an alternative if I did no...
more »

2017-07-30 23:07 (2) Answers

check if a number is a prime in bash

I am trying to write a bash script to find if a number is prime, but i can't find what is wrong with my script #!/bin/bash #set -x echo -n "enter a number " read isPrime count=2 x=0 while [ $count -lt $isPrime ]; do ...
more »

2017-07-29 19:07 (1) Answers

Bash - need help splitting a string by colon

I am having some trouble using IFS (as that is what the internet has led me to for this issue) - I keep getting an error saying "IFS: command not found" I am trying to split the string by ':' and store it in an array, so something that looks like a:b...
more »

2017-07-27 23:07 (2) Answers