1

I have a bash script with name test.sh existed in the folder c:/test

Problem Source:

The mainly reason to run bash in r, actually I have .nc4 files download with r and i would like to get its bandinfo by using gdalinfo in r which was more easy work in bash than in r. That why I have prepared another script in bash which can read these .nc4 files.

Search before posting

I search a function in r `system' but after setting path to the folder where my bash file exit i am trying this command in R

x <- "bash test.sh" #my bash file which i want to run in r
system(x, intern = TRUE,ignore.stdout = FALSE, ignore.stderr = FALSE, wait = TRUE, input = NULL, show.output.on.console = TRUE,minimized = FALSE, invisible = TRUE)

but getting this error

Error in system(x, intern = TRUE, ignore.stdout = FALSE, ignore.stderr = FALSE,  : 
  'bash' not found

Acknowledgements

highly thanks for resolving this problem. I am using Rstudio for the first.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • @hrbrmstr , the reason to use bash here actually its more easy in bash than r to get band by using gdalinfo. After getting my selective band from nc4 file i would like to crop this band with the help of my **shapefile** . Any easy approch u can guide me well dear? i have **ncdf4** package in r – Muhammad Usman Saleem Feb 25 '17 at 12:30
  • For those searching for something similar and finding this question, post a new question with complete details since this has many in-R answers but there's little point in trying to tease out info comment-by-comment here. – hrbrmstr Feb 25 '17 at 12:38
  • It would seem `bash` is not in your PATH? – Roman Luštrik Feb 25 '17 at 13:27
  • "I have a bash script with name test.sh existed in the folder **c:/test**" ... yeah, running a bash script ain't gonna work. – Hong Ooi Feb 25 '17 at 13:36
  • @RomanLuštrik dear , will you explain the `PATH` please. Is its meaning are path of my directory? – Muhammad Usman Saleem Feb 25 '17 at 14:52

1 Answers1

3

I have a bash script with name test.sh existed in the folder c:/test

You're using Windows, and bash scripts are meant for Unix/Linux. So that isn't going to work.

You have to install a bash shell to run bash scripts. You can try Cygwin for starters; see here for an example question on running bash scripts in Cygwin. Alternatively, if you're on Windows 10 you can install the bash for Windows subsystem. In the latter case, your Windows filesystem can be accessed via /mnt/<drive letter>. So the script c:\test\test.sh would be /mnt/c/test/test.sh.

Community
  • 1
  • 1
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • 1
    I am using Lunix commands on window using Cygwin and after setting its paths, I am calling it from **osgeo4w** . _bash_ sccript is running finely on window. Dear i want to call a bash script which deals with the nc files ( a protion of my r code) and i have to run this inside my for loop of r so that portion of my that code excute with bash.. **The problem is with the calling of bash file within rstudio, My question is about that** – Muhammad Usman Saleem Feb 25 '17 at 14:48
  • I have ubuntu for windows, setting the path as I would on ubuntu still doesn't let me run the .sh script. Idk if there's a way to tell it it should run it from ubuntu? (still looking obv, this thread is old, but if u got anything let me know) – Salix Apr 17 '20 at 17:29