bash - Check for invalid input in a menu

I am making a script where the user selects a number 1-5 and it will loop until the user enters 5. I don't want to use the exit command. I wanted to check to make sure the user doesn't enter anything but 1-5 and if they do display invalid input.any help would be appreciated#!/bin/bash PS3='Please enter your choice: 'options=("1.Move empty files" "2.Check file size" "3.Which files is newer" "4.File check rwx" select opt in "${options[@]}") while($opt != 5); do case $opt in "Option 1") echo "you chose choice 1" ;; ...Read more

bash - Running a script with upstart server in ubuntu 14.04

I have a script named After chmod +x, I can run it with the command /home/lin/Desktop/, and my screen will rotate left. #!/bin/bashxrandr --output VGA1 --rotate left Then I write a upstart job named testOne, located in /etc/init/testOne.conf. testOne.conf:description "test upstart job"author "Lin"start on filesystem or runlevel [2345]start on desktop-session-startstop on shutdownpre-start script mkdir -p /home/lin/Desktop/test1end scriptrespawnrespawn limit 15 5script exec /home/lin/Desk...Read more

translate - Translating strings to another language using bash

I have created a script that gets names and surnames of people both in latin and greek characters. My challenge was to translate all greek characters to latin ones in order to create more possible Facebook links to their profiles, but use only bash and nothing more, like python, ruby, etc.I have created something like a hash table file, which looks like this (look below) and follows a simple rule... Each record is separated with comma, the 1st field represents the number of additional ways of expression a letter has, the 2nd field represents th...Read more

shell - How to set a variable to the output of a command in Bash?

I have a pretty simple script that is something like the following:#!/bin/bashVAR1="$1" MOREF='sudo run command against $VAR1 | grep name | cut -c7-'echo $MOREFWhen I run this script from the command line and pass it the arguments, I am not getting any output. However, when I run the commands contained within the $MOREF variable, I am able to get output.I would like to know how one can take the results of a command that needs to be run within a script, save it to a variable, and then output that variable on the screen?...Read more

bash - Find overlapping ranges between different files

I have two files each with a column forming ranges.File 1 23241-24234 10023-12300 75432-82324 File 2 16722-17234 92000-94532 23600-25000 I am looking for ranges that overlap with a certain % (e.g. 50%) between the two files In the previous example only the following will be printed (50% overlap): 23241-24234 23600-25000I can do this using Python, but was wondering if there is a quicker bash command that would do the same thing....Read more

How do I tell if a regular file does not exist in Bash?

I've used the following script to see if a file exists:#!/bin/bashFILE=$1 if [ -f $FILE ]; then echo "File $FILE exists."else echo "File $FILE does not exist."fiWhat's the correct syntax to use if I only want to check if the file does not exist?#!/bin/bashFILE=$1 if [ $FILE does not exist ]; then echo "File $FILE does not exist."fi...Read more

applescript - Is there a way to make multiple files open in separate windows with a bash command?

I want to make a simple bash script that will open up 4 different text editor windows in 4 separate desktop spaces on my Mac.The closest solution I have is to transition the desktop by triggering an apple script between each atom call (atom is the text editor I'm using.) Right now it looks like thisprepare() { osascript -e "tell application \"System Events\" to key code 18 using command down" atom spec osascript -e "tell application \"System Events\" to key code 19 using command down" atom db osascript -e "tell application \"System Events\...Read more

How can I make a bash variable change a word between singular and plural endings based on a count of time?

I am not a good bash scripter yet. In the following example script, I am trying to move through steps, check the amount of time elapsed since the step started, and use the correct singular or plural ending to describe the amount of time that has passed. If the amount of time that passes rounds off to 1 second, I would like the script to tell me it took 1 "second" to move through the step and if it is anything else besides 1 second, I would like it to tell me it took x amount of "seconds"#!\bin\bashSTEP=0STEPS=4RUN=1while [ $RUN -eq 1 ]do if ...Read more

bash: recursively find the subdirectory which contains the largest number of immediate child files

I'm looking for a shell command to run in Bash which finds the subdirectory which contains the largest number of files. Execution time isn't a huge concern; it's clear that there will need to be a big trawl/sort operation to determine this result. The question is, how to compute this?My first thought was to use a command of the form find -type d -exec find {} -maxdepth 1 -type f | wc -l, but it turns out that you can't pipe within a find command like that....Read more

bash - Given a list of filenames (without paths), find the files within multiple subdirectories and copy those files to a destination folder

I need a way to take a .txt or .csv list of filenames as a source, search through a directory, under which there are multiple subdirectories (though not more than 2-3 levels), and copy the found files to a destination folder. I've not had success with this: for file in `cat ~/Desktop/filelist.txt`; do cp "$file" ~/Desktop; done...and rsync is failing me as well. I know there are multiple similar questions like this on here already, but I'm not finding a solution that works for me....Read more