-1

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

#!/bin/bash
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.

Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227

2 Answers2

3

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.

dogoncouch
  • 549
  • 2
  • 7
  • Sorry, I should have clarified, I ran `chmod +x` (that is not the same, I take it?) – SamAndrew81 Jul 19 '17 at 02: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
2

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.

marc
  • 2,317
  • 2
  • 16
  • 25
  • 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` – George Vasiliou Jul 19 '17 at 00:00