Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Bash Scripting help

Trying to make bash script to make handbrake encodes with CLI, but I run into a weird issue when creating folders.

 

Creating directories .sh file

mkdir test1
mkdir test2
mkdir test3

returns

mkdir: cannot create directory 'test1\r': No such file or directory
mkdir: cannot create directory 'test2\r': No such file or directory

And test3 gets created.

 

Same thing happens when I try to escape at EOL with \

 

What am I doing wrong?

CPU: Intel 4770k @ 4.6Ghtz MB: Asus z87-Deluxe RAM: 16GB Corsair Vengeance Red 1866mhtz Storage: Corsair Force 3 120GBx2 PSU: Corsair HX1000 GPU: ASUS GTX 780 DCU2 Case: Define R4

 

LTC: LeBdcWLcreZREjTRHJsi3vN4oRDVvqRNXf

 

Link to comment
Share on other sites

Link to post
Share on other sites

8 minutes ago, Nymmie said:

Trying to make bash script to make handbrake encodes with CLI, but I run into a weird issue when creating folders.

 

Creating directories .sh file


mkdir test1
mkdir test2
mkdir test3

returns


mkdir: cannot create directory 'test1\r': No such file or directory
mkdir: cannot create directory 'test2\r': No such file or directory

And test3 gets created.

 

Same thing happens when I try to escape at EOL with \

 

What am I doing wrong?

Semicolons?

Join the Appleitionist cause! See spoiler below for answers to common questions that shouldn't be common!

Spoiler

Q: Do I have a virus?!
A: If you didn't click a sketchy email, haven't left your computer physically open to attack, haven't downloaded anything sketchy/free, know that your software hasn't been exploited in a new hack, then the answer is: probably not.

 

Q: What email/VPN should I use?
A: Proton mail and VPN are the best for email and VPNs respectively. (They're free in a good way)

 

Q: How can I stay anonymous on the (deep/dark) webzz???....

A: By learning how to de-anonymize everyone else; if you can do that, then you know what to do for yourself.

 

Q: What Linux distro is best for x y z?

A: Lubuntu for things with little processing power, Ubuntu for normal PCs, and if you need to do anything else then it's best if you do the research yourself.

 

Q: Why is my Linux giving me x y z error?

A: Have you not googled it? Are you sure StackOverflow doesn't have an answer? Does the error tell you what's wrong? If the answer is no to all of those, message me.

 

Link to comment
Share on other sites

Link to post
Share on other sites

OK, that works to do with creating the folders, so thats progress, however, terminal output is

./test.sh: line 1 $'\r': command not found
./test.sh: line 2 $'\r': command not found

 

CPU: Intel 4770k @ 4.6Ghtz MB: Asus z87-Deluxe RAM: 16GB Corsair Vengeance Red 1866mhtz Storage: Corsair Force 3 120GBx2 PSU: Corsair HX1000 GPU: ASUS GTX 780 DCU2 Case: Define R4

 

LTC: LeBdcWLcreZREjTRHJsi3vN4oRDVvqRNXf

 

Link to comment
Share on other sites

Link to post
Share on other sites

11 hours ago, Nymmie said:

OK, that works to do with creating the folders, so thats progress, however, terminal output is


./test.sh: line 1 $'\r': command not found
./test.sh: line 2 $'\r': command not found

 

Remember to quote or mention me so I get a notification, it's a good thing I checked back manually.

You must have extra special characters (I believe \r is return, or an "enter" keystroke) because it works for me without semicolons even.

 

example.png

Join the Appleitionist cause! See spoiler below for answers to common questions that shouldn't be common!

Spoiler

Q: Do I have a virus?!
A: If you didn't click a sketchy email, haven't left your computer physically open to attack, haven't downloaded anything sketchy/free, know that your software hasn't been exploited in a new hack, then the answer is: probably not.

 

Q: What email/VPN should I use?
A: Proton mail and VPN are the best for email and VPNs respectively. (They're free in a good way)

 

Q: How can I stay anonymous on the (deep/dark) webzz???....

A: By learning how to de-anonymize everyone else; if you can do that, then you know what to do for yourself.

 

Q: What Linux distro is best for x y z?

A: Lubuntu for things with little processing power, Ubuntu for normal PCs, and if you need to do anything else then it's best if you do the research yourself.

 

Q: Why is my Linux giving me x y z error?

A: Have you not googled it? Are you sure StackOverflow doesn't have an answer? Does the error tell you what's wrong? If the answer is no to all of those, message me.

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, LtStaffel said:

Remember to quote or mention me so I get a notification, it's a good thing I checked back manually.

You must have extra special characters (I believe \r is return, or an "enter" keystroke) because it works for me without semicolons even.

 

example.png

oops... heres a curveball i forgot to mention... doing this on Windows with Linux on Windows Subsystem... and .sh made with notepad.

CPU: Intel 4770k @ 4.6Ghtz MB: Asus z87-Deluxe RAM: 16GB Corsair Vengeance Red 1866mhtz Storage: Corsair Force 3 120GBx2 PSU: Corsair HX1000 GPU: ASUS GTX 780 DCU2 Case: Define R4

 

LTC: LeBdcWLcreZREjTRHJsi3vN4oRDVvqRNXf

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Nymmie said:

oops... heres a curveball i forgot to mention... doing this on Windows with Linux on Windows Subsystem... and .sh made with notepad.

It's probably adding the return characters to the end. Try kate editor maybe? It's always been good in all my uses (on any OS)

Join the Appleitionist cause! See spoiler below for answers to common questions that shouldn't be common!

Spoiler

Q: Do I have a virus?!
A: If you didn't click a sketchy email, haven't left your computer physically open to attack, haven't downloaded anything sketchy/free, know that your software hasn't been exploited in a new hack, then the answer is: probably not.

 

Q: What email/VPN should I use?
A: Proton mail and VPN are the best for email and VPNs respectively. (They're free in a good way)

 

Q: How can I stay anonymous on the (deep/dark) webzz???....

A: By learning how to de-anonymize everyone else; if you can do that, then you know what to do for yourself.

 

Q: What Linux distro is best for x y z?

A: Lubuntu for things with little processing power, Ubuntu for normal PCs, and if you need to do anything else then it's best if you do the research yourself.

 

Q: Why is my Linux giving me x y z error?

A: Have you not googled it? Are you sure StackOverflow doesn't have an answer? Does the error tell you what's wrong? If the answer is no to all of those, message me.

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, LtStaffel said:

It's probably adding the return characters to the end. Try kate editor maybe? It's always been good in all my uses (on any OS)

yeah its Windows line endings but when i switch to Unix style i dont get the error, however line 1 ends up as command not found.

CPU: Intel 4770k @ 4.6Ghtz MB: Asus z87-Deluxe RAM: 16GB Corsair Vengeance Red 1866mhtz Storage: Corsair Force 3 120GBx2 PSU: Corsair HX1000 GPU: ASUS GTX 780 DCU2 Case: Define R4

 

LTC: LeBdcWLcreZREjTRHJsi3vN4oRDVvqRNXf

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, Nymmie said:

yeah its Windows line endings but when i switch to Unix style i dont get the error, however line 1 ends up as command not found.

@Nuluvius Save me

Join the Appleitionist cause! See spoiler below for answers to common questions that shouldn't be common!

Spoiler

Q: Do I have a virus?!
A: If you didn't click a sketchy email, haven't left your computer physically open to attack, haven't downloaded anything sketchy/free, know that your software hasn't been exploited in a new hack, then the answer is: probably not.

 

Q: What email/VPN should I use?
A: Proton mail and VPN are the best for email and VPNs respectively. (They're free in a good way)

 

Q: How can I stay anonymous on the (deep/dark) webzz???....

A: By learning how to de-anonymize everyone else; if you can do that, then you know what to do for yourself.

 

Q: What Linux distro is best for x y z?

A: Lubuntu for things with little processing power, Ubuntu for normal PCs, and if you need to do anything else then it's best if you do the research yourself.

 

Q: Why is my Linux giving me x y z error?

A: Have you not googled it? Are you sure StackOverflow doesn't have an answer? Does the error tell you what's wrong? If the answer is no to all of those, message me.

 

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, Nymmie said:

yeah its Windows line endings but when i switch to Unix style i dont get the error, however line 1 ends up as command not found.

Maybe this is because your script is executable and Windows Linux Subsystem tries to execute the first line differently from the rest of the lines.

59e76f31e16a4_Ekraanipilt2017-10-1818-04-40.png.e7d97a80ea46bc1775f5e3a09c98fd3a.png

I don't have a system handy to test this but try adding a shebang line as first line of your script.

 

something like this

#!/bin/bash

mkdir test1
mkdir test2
mkdir test3

And save the file as a UNIX file because as you already figured out Linux/Unix systems use \n as a line sperator instead of \n\r like Windows does.

Link to comment
Share on other sites

Link to post
Share on other sites

I just wrote a script that would run those same commands, and I got all three to run on Ubuntu 17.04 I haven't tried WSL.  I wrote it in nano, see if you can install that and then try rewriting the script.  

Spoiler

59e76f494a70c_Screenshotfrom2017-10-1810-11-44.png.528c6c201fb4b2afb4debfc74aaa00db.png

59e76fafe76b4_Screenshotfrom2017-10-1810-13-34.png.2ef29179905854f4c8babbd64e12d500.png

 

Here is what I wrote, like @artizirk said add the shebang line.  Also make sure that the script is executable

# !bin/sh


mkdir test1
mkdir test2
mkdir test3

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Linux seems to be pretty happy to run the script with broken shebang line but please

# !bin/bash
 ^ don't add a space here

correct bash shebang should look like this

#!/bin/bash
 ^ No space and it is a full path starting with a /

 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, artizirk said:

snip

Yeah, I taught myself an that is how I have always done it.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 10/17/2017 at 3:25 AM, Nymmie said:

Trying to make bash script to make handbrake encodes with CLI, but I run into a weird issue when creating folders.

 

Creating directories .sh file


mkdir test1
mkdir test2
mkdir test3

returns


mkdir: cannot create directory 'test1\r': No such file or directory
mkdir: cannot create directory 'test2\r': No such file or directory

And test3 gets created.

 

Same thing happens when I try to escape at EOL with \

 

What am I doing wrong?

Just install unix2dos and Dos2unix in your linux installation. And run Dos2unix test1 (test1 full path if not in the directory where test1 is located). This will convert windows line endings to linux so \r\n will become \n

\r\n is windows line ending

\n is unix line ending

Computer users fall into two groups:
those that do backups
those that have never had a hard drive fail.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×