I'm really stuck on my scripting because of this problem. I need my script to accept arguments and give me the result but since i have spaces it only displays the first word. eg.  cat open.sh echo My name is $1  export start=`date +"%b %d %k:%M:%S %Y"`  [oracle@spiderman scripts]echo $start Jul 01 3:03:18 2016  [oracle@spiderman scripts]$sh open.sh `echo $start` The time is Jul   I need the output as The time is Jul 01 3:03:18 2016.  I need to pass the same output to another complex script.
1847
Or, an introductory guide to robust filename handling and other string passing in shell scripts.  I wrote a shell script which works well most of the time. But it chokes on some inputs (e.g. on some file names).  I encountered a problem such as the following:   I have a file name containing a space hello world, and it was treated as two separate files hello and world. I have an input line with two consecutive spaces and they shrank to one in the input. Leading and trailing whitespace disappears from input lines. Sometimes, when the input contains one of the characters \[*?, they are replaced by some text which is is actually the name of files. There is an apostrophe ' (or a double quote ") in the input and things got weird after that point. There is a backslash in the input (or: I am using Cygwin and some of my file names have Windows-style \ separators).   What is going on and how do I fix it?
123931
It's high time to solve this conundrum that's been bothering me for years...  I've been meeting this from time to time and thought this is the way to go:  $(comm "$(arg)")   And thought my view was strongly supported by experience. But I'm not so sure anymore.  can't make up its mind too. It's both:  "$(dirname $0)"/stop.bash            ^-- SC2086: Double quote to prevent globbing and word splitting.   And:  $(dirname "$0")/stop.bash ^-- SC2046: Quote this to prevent word splitting.   What's the logic behind?   (It's Shellcheck version 0.4.4, btw.)
54700
I have a Python script which accepts string arguments.  $ python script.py "one image.jpg" "another image.jpg"   This works as expected.  Python argparse: ["one image.jpg", "another image.jpg"]    If I need to pass filenames I would do,  $ python script.py $(ls "/some/dir/*.jpg")   Python argparse: ["one", "image.jpg", "another", "image.jpg"]  If use the -Q of ls command, I can wrap results between double quotes. However, quotes stay escaped in Python script, ie.  $ python script.py $(ls -Q "/some/dir/*.jpg")   Python argparse: ['"one image.jpg"', '"another image.jpg"']    How should I expand ls filenames into proper strings to use as arguments? (as in my very first example)
36860
I am trying to run a bash script I have via cron, and I am getting the following error at the beginning of the execution:  tput: No value for $TERM and no -T specified   Here is what is in my crontab:  0 8 * * 1-5 cd /var/www/inv/ &amp;&amp; /var/www/inv/unitTest run all 2&gt;&amp;1| mail -r "user@example.com" -s "Daily Inventory Unit Test Results" user@example.com
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
30198
Say I have a script doing:  some-command "$var1" "$var2" ...   And, in the event that var1 is empty, I'd rather that it be replaced with nothing instead of the empty string, so that the command executed is:  some-command "$var2" ...   and not:  some-command '' "$var2" ...   Is there a simpler way than testing the variable and conditionally including it?  if [ -n "$1" ]; then     some-command "$var1" "$var2" ...     # or some variant using arrays to build the command     # args+=("$var1") else     some-command "$var2" ... fi   Is there a parameter substitution than can expand to nothing in bash, zsh, or the like? I might still want to use globbing in the rest of the arguments, so disabling that and unquoting the variable is not an option.
46580
I'm trying to escape the space char for a path in Bash, but neither using a  or  works.  .sh script:  ROOT="/home/hogar/Documents/files/" FILE=${ROOT}"bdd.encrypted" DESTINATION="/home/hogar/Ubuntu\ One/folder"  mv ${FILE} ${DESTINATION}   After execute the script (./file) this is the result:  mv: target 'One/folder' is not a directory   Why does the mv command split the string, and how do I stop this from happening?
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?
41595
I'm trying to join all of the arguments to a Bash function into one single string with spaces separating each argument. I also need to have the string include single quotes around the whole string.  Here is what I have so far...  $array=("$@") str="\'" for arg in "${array[@]}"; do     let $str=$str+$arg+" " done let $str=$str+"\'"   Obviously this does not work but I'm wondering if there is a way to achieve this?
1383
I want to enter the following folder in the terminal:  Milano, Torino (Jan)-Compressed   How should I write the command cd to enter this directory?  Spaces and several other special characters like \, *, ), ( and ? cause problems when I try to use them in the command line or scripts, e.g.:    $ cd space dir bash: cd: space: No such file or directory  $ cat space file cat: space: No such file or directory cat: file: No such file or directory  $ cat ( bash: syntax error near unexpected token `newline'  $ echo content &gt;\ &gt; ^C  $ ls ? (  )  *  ?  \   How do I enter file or directory names that contain special characters in the terminal in general?
70604
Let's say we have a Python script my_script.py that does some data processing with Blender. This script accepts some arguments (e.g. arg1 arg2). How can I forward arguments to the script when using it with the CLI?  blender --background --python my_script.py   The only trick I could find was :  echo "arg1 arg2" &gt; my_input.txt &amp;&amp; blender --background --python my_script.py   Is this really the only way to do that?  Update  I found a  on Stack Overflow.
84470
Suppose I have a bash shell script called Myscript.sh that need one argument as input.  But I want the content of the text file called text.txt to be that argument.  I have tried this but it does not work:  cat text.txt | ./Myscript.sh   Is there a way to do this?
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!
31808
I often have to do a recursive search in files. Tired of typing the whole "find/grep" combination all the time, I just created a script with the following line:  find . -name $1 -exec grep $2 {} + 2&gt;/dev/null   The idea is that I should be able to run it as, for example:  myfind '*' hello   The problem is, when '*' gets passed into the script, the script is expanding it to each file in the directory.  I tried putting a quote around $1:   find . -name '$1' -exec grep $2 {} + 2&gt;/dev/null   However, this turns $1 into a literal string.  Would appreciate your help in finding the right syntax. Must be something simple that I am missing.
69416
I'm learning how to create shell scripts on UNIX for a college class. The textbook says I should just be able to type the filename in my terminal and it should run, but so far I haven't been able to get that to work. But it works fine when I type in ./myscript. Currently, I am typing the scripts out on my Mac terminal, but I had FreeBSD loaded onto a virtual box and it was doing the same thing to me.  I think maybe I need to change my environment path? I remember I had to do that when I started writing python files.
2306
I am writing a bash script to look for a file if it doesn't exist then create it and append this to it:  Host localhost     ForwardAgent yes   So "line then new line 'tab' then text" I think its a sensitive format.  I know you can do this:  cat temp.txt &gt;&gt; data.txt   But it seems weird since its two lines. Is there a way to append that in this format:  echo "hello" &gt;&gt; greetings.txt
54303
If you take this code:  echo -e '\t\t\tString' | grep '^[\t]*String'   the result is blank because it doesn't match, yet this:  echo -e '\t\t\tString' | grep $'^[\t]*String'   works. I swear that I must have used the first line's code a hundred times in my scripts and in the terminal, without ever using the "$" character like that, and it's always seemed to work. Has there been some recent change? Why does it need the "$" character? Or am I doing something wrong?