Posts

Showing posts with the label shell

./ Dot Slash not working to execute Shell Scripts

Image
Clash Royale CLAN TAG #URR8PPP ./ Dot Slash not working to execute Shell Scripts I'm definitely a command line novice. I have recently lost the ability to execute shell scripts using ./script.sh I am still able to execute shell scripts using: sh script.sh My $PATH is as follows: /Users/goodguy/.pyenv/shims:/Users/goodguy/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/Users/goodguy/.rvm/bin I am using MacOS. I'd appreciate any insight into what I may be doing wrong Perhaps it doesn't have the executable flag set. Check with ls -lart script.sh and look for x . You can set it to executable using chmod +x script.sh – Matthew Darnell 14 mins ago ls -lart script.sh x chmod +x script.sh By clicking "Post Your Answer...

/bin/sh Need to identify file content type

Image
Clash Royale CLAN TAG #URR8PPP /bin/sh Need to identify file content type I'm working on busybox and have only /bin/sh available. I would like to understand if the file I'm processing with my script are to be treated as ASCII (just read and do what I need to do) or gzip (so unzip first then do what I need to do). The "file" command here would be perfect, but unfortunately it's just not available, hence I don't know what procedure to call as the input file I'm processing can be either format. I'm wondering if there's a simple workaround I'm missing here to find this out... What do you consider "non-ASCII"? Do you just need to test if your file has no characters with values outside 0-127? – Charles Duffy 13 mins ago You could check for the same magic number file l...

BASH case not catching empty string

Image
Clash Royale CLAN TAG #URR8PPP BASH case not catching empty string I want to detect if either no arguments or an invalid argument is passed and print a help message. A separate check for an empty argument is possible, but not so elegant. My bash script looks like this: COMMAND="$1" shift case "$COMMAND" in loop) loop_ ;; ... *) echo $"Usage: $0 {loop|...}" exit 1 esac When no arguments are passed, nothing executes; if I pass "" then the proper case is triggered. If I use $1 directly instead of using the temporary variable, then it works as expected. $1 I've even tried adding a specific case for "") but to no avail. "") Possible duplicate of Check existence of input argument in a Bash shell script – PesaThe 11 hours ago ...

Access Terminal and Run Shell Script in Ionic

Image
Clash Royale CLAN TAG #URR8PPP Access Terminal and Run Shell Script in Ionic I'm currently developing an app using Ionic framework and at some point, I need to access terminal to run a command. In my case, suppose I have an executable file which is named test.sh . normally in terminal, we can run it with ./test.sh (and I'm currently doing this with termux in anroid). Since I am using ionic, I don't have access to terminal nor a file executor. So my question is, how will I be able to execute a shell script using ionic? test.sh ./test.sh Thanks. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Parallel processes: appending outputs to an array in a zsh script

Image
Clash Royale CLAN TAG #URR8PPP Parallel processes: appending outputs to an array in a zsh script I have a for loop in which a function task is called. Each call to the function returns a string that is appended to an array. I would like to parallelise this for loop. I tried using & but it does not seem to work. task & Here is the code not parallelised. task (){ sleep 1;echo "hello $1"; } arr=() for i in {1..3}; do arr+=("$(task $i)") done for i in "${arr[@]}"; do echo "$i x"; done The output is: hello 1 x hello 2 x hello 3 x Great! But now, when I try to parallelise it with [...] for i in {1..3}; do arr+=("$(task $i)")& done wait [...] the output is empty. This question is specifically for zsh , for its bash counterpart please see here. zsh bash 2 Answers 2 I could be wrong, but I'm pretty sure you don't want to do...

Purposely aborting a Unix shell on an if condition

Image
Clash Royale CLAN TAG #URR8PPP Purposely aborting a Unix shell on an if condition I have created a shell script . I want to abort it on an if condition. I used exit command for example: exit 1 or exit 42. It doesn't fail the shell execution. Please help!! By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Error while pushing all *.gz files to aws s3 bucket - “bash: -c: line 0: syntax error near unexpected token `then'”

Image
Clash Royale CLAN TAG #URR8PPP Error while pushing all *.gz files to aws s3 bucket - “bash: -c: line 0: syntax error near unexpected token `then'” I am trying to push all *.gz files to aws s3 bucket but I getting this error bash: -c: line 0: syntax error near unexpected token `then' ssh root@ "find /tmp/ -name "localhost_*.gz" -mtime -1 -exec s3cmd put '{}' s3://script-testing/test1/ ; if [ $? == "0" ] ; then echo "Successfully pushed the backup to s3 bucket" | mail -s "Successfully pushed backup to S3 " email-id; else echo "Failed pushing logs to S3 Bucket" | mail -s "Failed Pushing logs to s3" email-id; fi" I checked syntax in shellcheck.net. It looks all good. But I don't know where is the issue. Any help would be greatful. – saranjeet singh Mar 7 '14 at 21:58 ...

How can I see file content in real time on Linux?

How can I see file content in real time on Linux? I have a log file which will be write some data in it continuously. How can I see what data is being written to the file on my Linux terminal without opening the file? 2 Answers 2 You can use tail 's -F option to follow in real time the changes made to your file: tail -F tail -F my_file.log Note: By default, tail prints the last 10 lines of your file. If you want to see more lines you can use the -n option: tail -n tail -F -n 50 my_file.log # See the last 50 lines in real time tail -f filename -n 100 tail -f filename -n 100 -n -> number of lines By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.