I have created a simple bash script called echo.sh. Which outputs a string. I've made sure its executable. And i then added it to the "startup applications" program through the GUI interface. However when i reboot my machine, it doesn't appear to of been executed, as there is no echo appearing in a terminal.  from my understanding shouldn't the script ,when executed, open up a terminal automatically from my understanding because of the STDOUT being the terminal file. However the script works fine if i launch it myself from the terminal.  echo.sh  #!/bin/bash  echo "hello this is a bash script talking"   Making it Executable  chmod +x echo.sh   Adding to "startup applications with correct directory to file"   Outcome  However when i reboot the system, the script doesn't run as expected, and no terminal appears with the echo message. I'm unsure as to why, and i may be completely missing the point, if so please let me know.  just to note, all my other bash scripts work , such as my "cleanup.sh" script which is also in the "startup applications" program.  Attempted fixes  I've tried redirecting the STDOUT to the terminal file /dev/tty. However this doesn't seem to work.  #!/bin/bash  echo "hello this is a bash script talking" &gt;/dev/tty   I've also tested a bash script with just a simple rm command, just to check if it was just the echo command that was having a problem. However when added to start up applications or .bashrc file, it doesn't delete the test.txt in the same directory as the script. However works when i execute manually from the terminal.  #!/bin/bash  rm ./test.txt   I've also tested startup applications program itself with just opening Firefox, with just the command Firefox. Which works without an issue. So their doesn't seem to be an issue with the startup applications program itself?
120554
I am trying to run a simple echo script via crontab. I set that to run every minute, but it doesn't give output on shell screen. However, it runs fine when I run the script independently.   Script  #!/bin/bash echo "Test Script"   Crontab entry:  root@example-server ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/     # For details see man 4 crontabs  # Example of job definition: # .---------------- minute (0 - 59) # |  .------------- hour (0 - 23) # |  |  .---------- day of month (1 - 31) # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # |  |  |  |  | # *  *  *  *  * user-name command to be executed   *  *  *  *  * root /root/test.sh
62806
I am currently trying to understand the difference between init.d and cron @reboot for running a script at startup/booting of the system.   The use of @reboot (this method was mentioned in  by hs.chandra) is some what simpler, by simply going into crontab -e and creating a @reboot /some_directory/to_your/script/your_script.txt and then your_script.txt shall be executed every time the system is rebooted. An in depth explanation of @reboot is   Alternatively by embedding /etc/init.d/your_script.txt into the second line of your script ie:  #!/bin/bash # /etc/init.d/your_script.txt  You can run chmod +x /etc/init.d/your_script.txt and that should also result for your_script.txt to run every time the system is booted.  Q1: What are the key differences between the two? Q2: Which is more robust? Q3: Is there a better one out of the two? Q4: Is this the correct way of embedding a script to run during booting?  I will be incorporating a bash .sh file to run during startup.
8591
I'm writing a simple desktop initiation script which waits for disk idle, and then launches next external program (like Firefox, Skype or ) using &amp;, like:  ps cax | grep conky &gt; /dev/null if [ $? -eq 0 ]; then   echo "Conky is already running." else   wait-for-disk-idle sda   conky &amp; fi   That's easy.   The problem is that some programs spew a lot of debug output to the terminal, which gets mixed with the messages produced by my initialization script.  The question:  Is there any way to asynchronously launch an external program so that its standard output is discarded?   What I already tried:   conky &amp; &gt;/dev/null 2&gt;/dev/null  bash -c conky &amp;     The correct answer:  bash -c "conky &gt;/dev/null 2&gt;/dev/null &amp;"
42910
I know how to redirect output and how to  in bash. Now, suppose I accidentally forgot to append the output redirection part to the command (e.g. 2&gt;&amp;1 or &gt; /tmp/mystdout) and my background process is already running for a while, can I still change to where stdout and stderr are being written to? I really would like not to kill and restart the application.  To be more specific as asked by  in his comment, I would like to fiddle with it in these scenarios in specific:   wrong output file forgot to redirect stderr to stdout   or a combination of both  E.g. I have Apache running and I can see the file descriptors:  /proc/8019/fd/0 -&gt; /dev/null /proc/8019/fd/1 -&gt; /dev/null /proc/8019/fd/2 -&gt; /var/log/apache2/error.log
83398
I'm using bash script on AMazon Linux.  When I want to redirect stderr and stdout to a file, I can run  ./my_process.pl &amp;&gt;/tmp/out.txt   Is there a way I can redirect this output to a file and continue to see it on the console (in my shell)?  How is this done?
110327
I have separate scripts for tasks in bash. Here is the broken one:  #!/bin/bash PATH=/home/name/ mkdir $PATH cd $PATH &amp;&amp; echo "done." exit 0   Today it broke and first time it simply didn't want to run cd, but created directory. Second time it just said "mkdir command not found." Running this commands exactly with semicolon works fine. What the case?
84443
Is there a way to create and execute a script file in Ubuntu 14.04?  Perhaps something like Windows batch files.  Specifically, I mean the default scripting language of the Ubuntu terminal (Bash).  How do you make a text file containing bash commands which will be run by the Ubuntu terminal from the top of the file to the bottom.
71756
I want to run a simple bash script automatically when I log in. For example  #!/bin/bash echo "start spotify" gnome-terminal -e spotify --title spotify   When I run this command, one gnome-terminal shows up and spotify show up. I also want the gnome-terminal to popup "hidden" in a different virtual desktop. (one of the other four virtual desktops you can choose from taskbar)   I tried to add this to /home/me/.bash_login or something, but that didn't work..
16488
Currently I have a shell script which logs messages to a log file like this:  log_file="/some/dir/log_file.log" echo "some text" &gt;&gt; $log_file do_some_command echo "more text" &gt;&gt; $log_file do_other_command   When executing this script, there is no output to screen, and, since I'm connecting to the server via putty, I have to open another connection and do "tail -f log_file_path.log", because I can't terminate the running script and I want to see the output in real time.  Obviously, what I want is that the text messages are printed on screen and into file, but I'd like to do it in one line, not two lines, one of which has no redirection to file.  How to achieve this?
16777
Some GUI apps launch cleanly via the Terminal command line, but some don't, and they cause the Terminal to wait for the app to terminate. Even then, some don't "release" the command line.  The mysterious ampersand &amp; suffix seems to cause the terminal to put the process into the background (but I'm not sure what happens there).  Is there a way to launch an app via the Terminal so that there is no "hang on" effect, just like launching something via Alt+F2?  I'd like to have the command line available again immediately, without something still in the background and printing in the terminal.
26653
I know that shell scripts just run commands as if they were executed in at the command prompt.  I'd like to be able to run shell scripts as if they were functions... That is, taking an input value or string into the script.  How do I approach doing this?
34361
I have one bash source run.sh as follows,  #!/bin/bash if [ $# -ne 1 ]; then     exit fi ...   when I execute it in two ways, there are different behaviors. The first way is,  source run.sh   It will close the terminal after execution. The second way is,  ./run.sh   this will simply finish running the script, and stay on the terminal. I am asking if there is a command for exiting a bash scripts for both source run.sh and ./run.sh execution. I have tried return too, which does not work well under ./run.sh execution.  More generally, I am interested in why this is happening, and what's difference between using "source" and "." for script execution?
90845
I have a couple of scripts in my bash file, that should do certain tasks, say like ...   #!bin/bash yum -y update service restart nginx yum install atop cat /var/log/somelog.log &gt; /home/cron/php/script   It goes on and on, but the problem is that with each task taken, bash shows me the output. Like  service restart nginx for example, outputs some message. And I want to hide all these messages. What is generally the accepted way of achieving this? Because, I was about to redirect the STDOUT to /dev/null but, considering I have over 50 consecutive tasks to run, it would mean I have to /dev/null that much, which for some reason does not seem efficient to me.
10006
I have a shell script. I want to configure my script to run automatically during startup. I know how to do this from GUI. But I wanted to do this from terminal. How can I do this?  On a primary research I found that the file needs to be moved to /etc/int.d/ directory. But this operation needs sudo permission. I wanted to do this without super user permissions.   I also found that there are files under ~/.config/autostart/ which are having some settings regarding the startup applications. But I don't know how to edit them to achieve this.   Can someone tell me the exact procedure to achieve this?
18498
Suppose you have a terminal emulator (T1) open with a PID of 6350.  From another terminal, type this command (C1):  echo "ls\n" &gt; /proc/6350/fd/0   This writes ls and the new line in T1 but does not execute it. Why?  I also tried using cat|bash with echo "ls\n" &gt; /proc/catid/fd/0 but it is still not executed.  How can I echo the command into another terminal and have the command executed?  possible answer :  $ mkfifo toto; $ bash &lt; toto; $ echo "ls" &gt; toto;   In this case you cannot write anymore directly in the terminal (everything is displayed the same way the command (C1) displayed thing in this terminal.
64012
I have a Python script which I would like to execute at every startup. I can run it by adding this to the startup applications:  python3 /path/to/script.py   That works, but it doesn't open a terminal window, so I can't see the program's output. How could I make it open a terminal window and execute the script in there?  Note: I get the window to stay open with input(' ') at the end of the Python script. Thanks!
120370
I have been teaching myself bash scripting and have run into an issue. I have written a script to take input from the user, using the 'read' command, and make that input a variable to use later in the script. The script works, but....  I would like to be able to get it setup using 'dialog'. I found out that  'dialog --inputbox' will direct the output to 'stderr' and in order to get that input as a variable you have to direct it to a file and then retrieve it. The code I found to explain this is:  #!/bin/bash dialog --inputbox \  "What is your username?" 0 0 2&gt; /tmp/inputbox.tmp.$$  retval=$?  input=`cat /tmp/inputbox.tmp.$$`  rm -f /tmp/inputbox.tmp.$$  case $retval in 0)  echo "Your username is '$input'";; 1)  echo "Cancel pressed.";;  esac   I see that it is sending the sdterr to the /tmp/inputbox.tmp.$$ with 2>, but the output file looks like 'inputbox.tmp.21661'. When I try and cat the file it gives me an error. So I am still unable to get the user input from the --inputbox as a variable.   Example Script:   echo "  What app would you like to remove? "  read dead_app  sudo apt-get remove --purge $dead_app   So as you can see it is a basic script. Is it even possible to get the variable as a word from dialog --inputbox?