I have the following prompts  [/share/registrazioni/Script] # cat delete_7gg.sh #!/bin/sh find /share/registrazioni/ -type f -mtime +7 -delete [/share/registrazioni/Script] # which sh /bin/sh [/share/registrazioni/Script] # chmod +x delete_7gg.sh [/share/registrazioni/Script] # ./delete_7gg.sh -sh: ./delete_7gg.sh: /bin/sh^M: bad interpreter: No such file or directory   why do I get /bin/sh^M: bad interpreter: No such file or directory ? I made the script with vi. I made the script in a qnap qts 4.3.6 that I can reach via ssh.  The script should simply delete files older than seven days.  I can't install dos2unix because the system has no package manager.  I just expected to make a script and put it into cron. but I'm receiving that error instead.
121619
Why are the shebang parts of the following elementary scripts not working:  $ cat hello.sh #! /bin/sh echo Hello $ ./hello.sh bash: ./hello.sh: /bin/sh^M: bad interpreter: No such file or directory  $ cat hello.py #! /usr/bin/env python3 print("Hello") $ ./hello.py : No such file or directory   whereas calling the interpreter manually is working:  $ sh hello.sh Hello $ python3 hello.py Hello
25455
I have a script in a folder:  /path/to/my/script.sh   I need this script to run every time the system starts (even if no one logs in to the system). What do I need to do in order to make this happen?
100567
This is from . It's about executing a Perl script.     Finally, if you are unfortunate enough to be on an ancient Unix system   that doesn’t support the magic #! line, or if the path to your   interpreter is longer than 32 characters (a built-in limit on many   systems), you may be able to work around it like this:   #!/bin/sh -- # perl, to stop looping eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0;   Can you explain step by step what's going on here? I'm trying to make it work or encompass, but to no avail.  At execution of just the above, I'm getting this:  /bin/sh: 0: Illegal option --
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?
103411
Some time ago I erroneously deleted my home folder because I ran a rm -rf * on the wrong terminal, whose working directory was the home folder!  I wish I had an alias for the rm command, but it was not the case.  Now, I am planning to make a script as an alias for rm.  Do you have any best practice to suggest?  Thanks.
70834
Here's the script code I'm using now:  getent group $MYGROUP if [ $? -ne 0 ] ; then     sudo su -c "groupadd $MYGROUP" fi sudo su -c "useradd mynewuser -p mypassword -m -g $PRIMARYGRP -G $MYGROUP"   This approach works well on openSuse. But there are several problems with the user account it creates on Ubuntu so I am seeking help here.   the terminal prompt isn't set (echo $PS1 returns nothing) the arrow keys and tab key do not work correctly in the terminal the password doesn't seem to work (although I'm still unclear exactly what this issue is) the /etc/sudoers rights set for this new user are not honored   If instead I manually create the user with adduser (instead of useradd) I don't have these problems on Ubuntu. But I can't use adduser on openSuse (afaik). Therefore, I need a non-Debian-exclusive script or method of adding user accounts via my bash script that works on Ubuntu (and doesn't stop working on other distros).  Finally, I would like to understand  between adduser and useradd. For example, I want to know which skeleton directory is used by adduser as that might be the reason useradd isn't working as expected (because I just accepted the default).   Thanks
5146
I've created a bash script but when I try to execute it, I get   #!/bin/bash no such file or directory   I need to run the command: bash script.sh for it to work.  How can I fix this?
101452
I would like to write a set of shell scripts which would execute smoothly on Mac disregarding where they are called from.  I am currently struggling about how to implement this.  On windows, I could write three batch scripts  A.bat in folder A B.bat in folder Subfolder, which is subfolder of A and which path is A/Subfolder C.bat in folder Subfolder, which is subfolder of A and which path is A/Subfolder  In A.bat I could write  call Subfolder/B.bat   in B.Bat I could write  call C.bat   and both scripts A and B would execute successfully.  On Mac, however, I have to prepend ./ to every script so that it is recognized as script.  So when I write in a.sh code:  Subfolder/b.sh   and then in b.sh code  ./c.sh   when I execute ./b.sh from terminal it is executed successfully.  However, when I execute ./a.sh from a parent folder in terminal, it fails with error   ./a.sh Subfolder/b.sh: line 1: ./c.sh: No such file or directory    Is this possible on Mac to write a code in b.sh which would execute disregarding if it is called from the current folder or from the parent folder?
65730
I've seen this message several times whenever someone has a problem installing, upgrading or removing some piece of software, but I wonder, what does it mean, and more importantly, is possible to solve it?  (Reading database ... 81657 files and directories currently installed.)  Removing mongodb-10gen ...  arg: remove  invoke-rc.d: unknown initscript, /etc/init.d/mongodb not found.  dpkg: error processing mongodb-10gen (--remove):   subprocess installed pre-removal script returned error exit status 100  invoke-rc.d: unknown initscript, /etc/init.d/mongodb not found.  dpkg: error while cleaning up:   subprocess installed post-installation script returned error exit status 100  Errors were encountered while processing:   mongodb-10gen  E: Sub-process /usr/bin/dpkg returned an error code (1)   (the above is just an example, not my actual problem)
117402
I created a new user with useradd name and forgot to use -d -m to create their home directory.  I tried making one, copying the contents of /etc/skel, and chowning everything to the new user.    Aliases don't work, such as ll, and I just have a $ at the command prompt, instead of name@server ~$. Also, using the scroll wheel dumps garbage on the command line :(  How do I fix this, or is it easier to delete the user and start over?
94692
I have a script called jsl in /usr/local/bin. Running which jsl finds it there.  I want to temporarily use a different version, and when I echo $PATH I see that /usr/bin is earlier in the path. So I added a script called jsl in that folder and I've verified that it is executable and runs correctly when called with the full path.  However, which jsl still finds the first version, and jsl still runs it.  Why isn't my new jsl being found by which or executed by name?
85720
I installed QGIS 3, and tried to execute tools like "sieve" "merge" and "polygonize". All of them gave me the error message:  GDAL command output: /bin/sh: (scriptname).py: command not found   I found the scripts in both /Username/miniconda3/bin and /Username/miniconda3/lib/python3.6/site-packages/GDAL-2.2.2-py3.6-macosx-10.9-x86_64.egg-info/scripts.  Checking env in Terminal shows that miniconda3/bin is in the path:  PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin://Users/Username/miniconda3/bin  What could be causing the failure of executing those scripts?
82155
This is my script:  #!/bin/bash hd='pwd' cd $hd   When I try to run it, it fails with:  line 3: cd: $'pwd\r\r': No such file or directory   What is going on?
33396
Here's my source:  #!/bin/bash  echo "Running script to free general cached memory!" echo ""; echo "Script must be run as root!"; echo ""; echo "Clearing swap!"; swapoff -a &amp;&amp; swapon -a; echo ""; echo "Clear inodes and page file!"; echo 1 &gt; /proc/sys/vm/drop_caches; echo "";   It clears caches and stuff, and it echoes that it needs to be run as root in the terminal. I basically just want the script to cease running if it detects it's not being executed as root.   Example:  "Running script to free general cached memory!" "Warning: script must be run as root or with elevated privileges!" "Error: script not running as root or with sudo! Exiting..."   If run with elevated privileges, it just runs as normal. Any ideas? Thanks!
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.
103349
I don't get this:  script: WORKDIR/sh/script.sh  [ -e filename ]          \ &amp;&amp; echo filename         \ || [ -e ../filename ]    \ &amp;&amp; echo ../filename      \ || { echo 'ERROR: failed to find "filename"' 1&gt;&amp;2 ; exit -1; }   output:  $ cd WORKDIR/sh $ ./script.sh ../filename  $ cd WORKDIR $ sh/script.sh filename ../filename      # &lt;---- WHY????   My thoughts:  1  [ -e filename ]          \ -&gt; false &amp;&amp;                         -&gt; skip this, it is already false    echo filename         \ -&gt; don't even try || [ -e ../filename ]    \ -&gt; true &amp;&amp; echo ../filename      \ -&gt; true ||                         -&gt; already true, skip the rest    { echo 'ERROR: failed to find "filename"' 1&gt;&amp;2 ; exit -1; }   2  [ -e filename ]          \ -&gt; true &amp;&amp; echo filename         \ -&gt; true ||                         -&gt; already true, skip the rest    [ -e ../filename ]    \ &amp;&amp; echo ../filename      \ || { echo 'ERROR: failed to find "filename"' 1&gt;&amp;2 ; exit -1; }   version:  bash --version GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)
74016
Trying to set up a daily cron job to shut down a server.   One source suggests editing /etc/crontab  Another suggests crontab -e (with sudo)  I tried the latter, and my process did not run (if I recall, it was 30 23 * * * shutdown -h)   I also note that in the nano editor, it was working on a .tmp file? (top of nano says: /tmp/crontab.9zeTNt/crontab )  What is going on? How can I fix this?