I am working on a project to calculate my overtime at work with a shell script.  I have two inputs and want to find if my number is over 800 = 8 hours; if it is bigger, then it has to print out the result to my text file.  It has to print out my difference.  if [ $var1 -gt 800 ]; then `expr $var1-800` echo Overtime: "" &gt;&gt; $path    and then I'm lost because I don't how to print out the result of my calculation.
121090
My question is kinda long Im trying to make a check in and out system simple, a menu with options 1 checkin and 2 checkout at the end of the day when I go home. My file contains:  Dato: 22-02-2018     Mødt ind: 700     Gået hjem: 1600     Overtid:     Dato: 23-02-2018     Mødt ind: 730     Gået hjem: 1600 Overtid:   I gotta find difference for 730 and 1600 in this file.. and if the number is higher than 800 it gotta print the number if there is a difference  hope you understand my question
105773
I would like to display the completion time of a script.   What I currently do is -  #!/bin/bash date  ## echo the date at start # the script contents date  ## echo the date at end   This just show's the time of start and end of the script. Would it be possible to display a fine grained output like processor time/ io time , etc?
46307
I wanted to capture to a file the errors being returned on the command line from grep. For example,  grep foo.lookup No such file in directory   I want to output that to a log file. This is my shell script:  lookUpVal=1 var1=$(grep $lookUpVal foo.lookup) &gt;&gt;lookup.log 2&gt;$1   It creates the file lookup.log but doesn't write the error on it.
16837
I've written a quick-and-dirty script to time some reports from a web service:  BASE_URL='http://example.com/json/webservice/' FIRST=1 FINAL=10000  for report_code in $(seq 1 $FINAL); do   (time -p response=$(curl --write-out %{http_code} --silent -O ${BASE_URL}/${report_code}) ) 2&gt; ${report_code}.time    echo $response  # &lt;------- this is out of scope!  How do I fix that?   if [[ $response = '404' ]]; then     echo "Deleting report # ${report_code}!"     rm ${report_code}   else     echo "${report_code} seems to be good!"   fi done   I need to wrap the time command in a subshell so I can redirect its output, but that makes the value of $response unavailable to the parent shell.  How do I get around this problem?
110737
I want to get the result of time command into a text file but it's not working it only put blank space in the text file.  I already tried this commands,  A-  $ x=`time` $ echo $x &gt; log.txt $ cat log.txt  $   B-   $ time &gt; log.txt  real    0m0.000s user    0m0.000s sys     0m0.000s $ cat log.txt  $   C-  $ time &gt; log.txt 2&gt;&amp;1  real    0m0.000s user    0m0.000s sys     0m0.000s  $ cat log.txt  $    What I really want is this.   $ time &gt; log.txt $ cat log.txt  real    0m0.000s user    0m0.000s sys     0m0.000s
66729
I want to compare two floating point numbers in a shell script. The following code is not working:  #!/bin/bash    min=12.45 val=10.35     if (( $val &lt; $min )) ; then       min=$val fi echo $min
38993
I am new to UNIX and am trying to learn basic level text processing in UNIX so maybe this question may seem very basic but I would really appreciate any guidance.  I have a text file as below  A 1 B 2 C 9 D 1 A 5 B 3 C 4 A 6 C 7 A 5 C 1   for which I was able to piece together a command with some help as below  cat | awk 'BEGIN{OFS=FS=" "}!(($1,$2)in c){c[$1,$2]=1;r[$1]=r[$1] OFS $2} END{for(i in r){print i r[i]}}'   inside a shell script to get it to the format below:  A 1 5 6 5 B 2 3 C 9 4 7 1 D 1   My shell script will also take an argument k  (=7 say)  In this case, my script should sample 1 element from each box (A,B,C,D) until it has a total of 7 elements sampled. This will be like follows: First pick 1 from A, then 2 from B, 9 from C, 1 from D, 5 from A, 3 from B, 4 from C and display  A 1 5 B 2 3 C 9 4 D 1   If instead I had k = 9 as my input, then my output should be  A 1 5 6 B 2 3 C 9 4 7 D 1
49040
for i in $(xrandr); do echo  "$i" ; done for i in "$(xrandr)"; do echo "$i"; done for i in "$(xrandr)"; do echo $i; done   I understand why 1 differs from 2. But why does 3 give a different output from 2? Please explain the output too. How do quotes work on newlines?
86103
I want to write a script to return just the extension of the input file name. For example, textfile.txt should return txt.  I'm new to Linux and bash, and I'm trying to learn how to write basic scripts. Thanks!
121409
My script (should) acts differently, depending on the presence of the data in the input stream. So I can invoke it like this:  $ my-script.sh   or:  $ my-script.sh &lt;&lt;-MARK     Data comes...     ...data goes. MARK   or:  $ some-command | my-script.sh   where two last cases should read the data, while first case should notice the data is missing and act accordingly.  The crucial part (excerpt) of the script is:  #!/bin/bash local myData; read -d '' -t 0 myData;  [ -z "${myData}" ] &amp;&amp; {     # Notice the lack of the data. } || {     # Process the data. }   I use read to read input data, then option -d '' to read multiple lines, as this is expected, and the -t 0 to set timeout to zero. Why the timeout? According to  (typing left unchanged; bold is mine):     -t timeout time out and return failure if a complete line of input is               not read withint TIMEOUT seconds.  The value of the TMOUT               variable is the default timeout.  TIMEOUT may be a               fractional number.  If TIMEOUT is 0, read returns success only               if input is available on the specified file descriptor.  The               exit status is greater than 128 if the timeout is exceeded   So I in case 2 and 3 it should read the data immediately, as I understand it. Unfortunately it doesn't. As -t can take fractional values (according to above man page), changing read line to:  read -d '' -t 0.01 myData;   actually reads the data when data is present and skips it (after 10ms timeout) if it is not. But it should also work when TIMEOUT is set to real 0.  Why it actually doesn't? How can this be fixed? And is there, perhaps, alternative solution to the problem of "act differently depending on the presence of the data"?  UPDATE  Thanks to @Isaac I found a misleading discrepancy between quoted on-line version and my local one (normally I do not have locale set to en_US, so help read gave me translation which I couldn't paste here, and looking up for on-line translation was faster than setting new env---but that caused the whole problem).  So for 4.4.12 version of Bash it says:     If TIMEOUT is 0, read returns               immediately, without trying to read any data, returning               success only if input is available on the specified               file descriptor.   This gives a little bit different impression than "If TIMEOUT is 0, read returns success only if input is available on the specified file descriptor"---for me it implied actually an attempt to read the data.  So finally I tested this and it worked perfectly:  read -t 0 &amp;&amp; read -d '' myData;   The meaning: see if there's anything to read and if it succeed, just read it.  So as to base question, the correct answer was provided by Isaac. And as to alternative solution I prefer the above "read &amp;&amp; read" method.
35975
The variable BUILDNUMBER is set to value 230. I expect 230_ to be printed for the command echo $BUILDNUMBER_ but the output is empty as shown below.  # echo $BUILDNUMBER_  # echo $BUILDNUMBER 230
16732
I'd like to have a time, say 6:45am, and add an amount of hours, say 1.45 hours, to result in another time. So I'd like to add 1.45 hours to 6:45am to get another time.   Is there a command line utile for that? I've done some Googling, and read the man page for date and haven't found anything like that. wcalc doesn't seem to handle time calculations.  EDIT: Mar 6, 2015. This is the script I ended up with to use decimal hours. It could use some error checking to make sure HH:MM uses 2 digits for the hours.  #!/bin/bash # Mar 6, 2015 # Add decimal hours to given time.  # Syntax: timeadd HH:MM HOURS # There MUST be 2 digits for the hours in HH:MM. # Times must be in military time.  # Ex: timeadd 05:51 4.51 # Ex: timeadd 14:12 2.05 echo " " # If we have less than 2 parameters, show instructions and exit. if [ $# -lt 2 ] then     echo "Usage: timeadd HH:MM DECHOURS"     exit 1 fi intime=$1 inhours=$2 # Below is arithmetic expansion $(()) # The bc calculator is standard on Ubuntu.  # Below rounds to the minute.  inminutes=$(echo "scale=0; ((($inhours * 60)*10)+5)/10" | bc) echo "inminutes=$inminutes" now=$(date -d "$intime today + $inminutes minutes" +'%H:%M') echo "New time is $now"
47782
I am trying out the command  $ b=5; echo `$b`; -bash: 5: command not found   but it does not print 5 as it is supposed to. What am I missing here?   seems to say that ` evaluates the commands within and replaces them with the output.
73123
there is a script I evolved with it, it has line of command like below :  mytemp=`echo ${sourcedir}|awk -F/ '{printf "/%s/tmp",$2}'`/`basename $0`-$1.$$   at the last of the command we see $$ that produces a number. when I use echo $$ in bash I also see a number like bellow:   #echo $$  23019   what exactly is this number, and what is $$?
100860
I started working on a script to rename files based on timestamp.  I thought I had it worked out on the command line but not working as a script.  Script hangs in the awk line.  This is the little script so far.  #!/bin/bash #renamePhotos.sh #  a script to rename photos in current directory based on date #  to be expanded  #  OUTPUT in $(ls -tr *.JPG);  LIST="$(ls --full-time -tr *.JPG)" echo "Starting..."  for i in "$LIST"; do     echo  $(awk '{ print $6 }' | awk 'BEGIN { FS = "-" }; { print $1 }')     echo done
45767
I am seeing different results from the find command between being run manually on the command line vs run in a script.   If I run the following on the command line:   find . -name '*.txt' ! -name '*20120427.txt'    I get all the .txt files in a directory except for the ones with the date that I want to avoid.  But when I have this same line in a script with a variable to identify the date:  FDATE=`date +%Y%m%d` find . -name '*.txt' ! -name '*${FDATE}.txt'    The script finds all the .txt files including the ones with the date I want to avoid.   The only difference between the 2 is that I am passing the FDATE variable in the script. Is there something obvious I am missing? I do not understand why the results are coming out different.
22833
I want to test if there is any output from the diff (test if files are same), if none echo "Passed $x" else echo "Failed $x". I came up with some intermidiate step (save the output from diff to a file then read from file)  diff "./helloworld$x.out" "./output/helloworld$x.out" &gt; tmp.txt; output="`cat tmp.txt`";  if [ "$output" = "" ];   then     echo "Passed $x";   else     echo "Failed $x";   fi;   I'm sure the code can be improved? Main question is: is it possible to save the output from diff directly into a variable?