I have a simple bash file script that sets proper resolution for my VM (1920x1080) in Linux Mint v18.1:

xrandr --newmode "1920x1080"  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync 
xrandr --addmode Virtual1 1920x1080
xrandr --output Virtual1 --mode 1920x1080`

Worth noting, I originally had this script living on my desktop, but I have since copied it to /etc/init.d/ but it still does not run without appending bash -x before ./script.sh Can anyone tell me why this is and what I can do to fix it?

EDIT: I was just attempting to run the script incorrectly (I blame PowerShell):
noob_me@linux-mint$ .\reso.sh .reso.sh: command not found

Once I ran it like so ./script.sh it works fine.

  • 1
    update question to show what happens if you try ./script.sh alone ?
    – steve
    Jul 18 '17 at 21:51
  • 1
    Use a forward slash instead of a backslash. And I don't know why it would work with bash -x .\script.sh; it shouldn't. The backslash will be removed, so .script.sh should be the result.
    – Wildcard
    Jul 18 '17 at 21:53
  • I suppose thats a typo...
    – marc
    Jul 18 '17 at 21:58
  • Related, possible duplicate: unix.stackexchange.com/q/136547/135943
    – Wildcard
    Jul 18 '17 at 22:09
  • 1
    I wonder if you wrote the script in an editor that put carriage returns and newlines in instead of just newlines?
    – Jeff Schaller
    Jul 19 '17 at 2:19

You need to add execute permissions to the file, if you haven't already, in order to run it on its own. You can do that with chmod. chmod u+x filename will add execute permissions for the file owner, chmod a+x filename will add them for everyone.

  • Sorry, I should have clarified, I ran chmod +x (that is not the same, I take it?) Jul 19 '17 at 2:04
  • @SamAndrew81 chmod +x seems to have the same affect as chmod a+x. If it's still not working, what is the error message that you get when you try to run it? Without the error message, we're all just guessing in the dark.
    – dogoncouch
    Jul 19 '17 at 15:06

If the script runs with bash -x, then it also runs without it, as the only thing which bash -x <file> does, is running the script in debug mode by tracing each executed command.

  • 2
    bash -x is not only enabling the debug mode - it is also calling the bash interpreter explicitly and this makes the script to run. If the script has not execute permissions you can run it either with bash -x file.sh or with a plain bash file.sh , but not with ./file.sh Jul 19 '17 at 0:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.