-2

I am new to scripting. While looking at an ex-employee's R code there's a line where they call to the command line. The line/purpose is not something I know how to search for online. Any help is appreciated.

The line of code in question:
/folder1/folder2/folder3 -s file_1_name -n file_1_name -e file_2_name > file_1_name.log 2>&1

Things to note:
The syntax is bash (or derived from bash, 2>&1), though when I use the command line to check what shell is used it says tcsh (example redirect >&, no numbers).\

File names (above) are just the name, not the extension. Example: a file named "ex.sch" then file_1_name would be "ex". The only extension in the line of code is for the log file that is made.

The files are .sch files. According to this site these are for schematics, though I highly doubt that that's what they are.

neilfws
  • 32,751
  • 5
  • 50
  • 63
Ryan S
  • 73
  • 6
  • `/folder1/folder2/folder3` is likely the script name (so `folder3` may not be a folder?). There is no way we can know anything about the files, their extensions, or how this shell script deals with its arguments ... since that's all they are, *arguments*. If they happen to correspond to filenames (or close to them), that's convenient, but nothing we can know here. The `2>&1` is bash's redirection of stderr onto stdout; this is so that all output (both normal stdout and anomalous stderr) go to the same output file. – r2evans Feb 09 '21 at 01:39
  • The fact that they are `.sch` files is a red herring as far as we can tell. – r2evans Feb 09 '21 at 01:40
  • 2
    I can't tell what your question is. – glenn jackman Feb 09 '21 at 01:52
  • Your shell may be csh but that doesn't prevent this line of code from being executed by bash if you found it inside a script (does the script really begin with `#!/bin/tcsh` or is tcsh just your personal shell?). Under Unix, file extensions are usually not necessary, it's only an help for humans and programs will work without. I'm not sure to understand your exact problem: does the command fail? – xhienne Feb 09 '21 at 01:52
  • "Please explain this code" questions are almost always by nature too broad to be on-topic here. See [How to handle "Explain how ${this code dump} works" questions?](https://meta.stackoverflow.com/questions/253894/how-to-handle-explain-how-this-code-dump-works-questions) on [meta]. – Charles Duffy Feb 09 '21 at 02:01
  • @RyanS : _when I use the command line to check what shell is used it says tcsh_ : **How** exactly did you check this? – user1934428 Feb 09 '21 at 07:59
  • @RyanS : _File names (above) are just the name, not the extension_ Why then, if you have this kind of question, aren't you displaying exactly the R-command which is going to be executed? – user1934428 Feb 09 '21 at 08:01
  • 1
    @r2evans: turns out you are correct. The file didn't have any extension, so I thought it was a folder. New to CLI and didn't know green text from "ls" command means executable. – Ryan S Feb 11 '21 at 19:02
  • @xhienne: thank you, that helped. I've not used shebangs before. Turns out that was it, there's a shebang for bash at the top; I though it was just a removed comment. – Ryan S Feb 11 '21 at 19:02
  • @user1934428: There's a command I found online, I didn't write it down, but it's something like echo "$SHELL" – Ryan S Feb 11 '21 at 19:02
  • I hope you don't blindly copy and paste commands you find online, without having at least a rough idea what they are doing. This will bite you sooner or later.... – user1934428 Feb 12 '21 at 07:51
  • @user1934428: I know "echo" just prints whatever to the console, so I figured it was safe. I will definitely exert caution, though, especially when it comes to command lines. – Ryan S Feb 13 '21 at 15:05

1 Answers1

1

The line/purpose is not something I know how to search for online. [...]

The line of code in question:

/folder1/folder2/folder3 -s file_1_name -n file_1_name -e file_2_name > file_1_name.log 2>&1

Interpreted as a Bash command line, that is executing the program or script /folder1/folder2/folder3, passing it the six command-line arguments -s file_1_name -n file_1_name -e file_2_name. It is furthermore directing the program's standard output and standard error to a file named file_1_name.log in the working directory, creating that file if it does not already exist and replacing its contents if it does. If the command works then folder3 must in fact be a regular file or a symbolic link to one, not a directory / folder.

We cannot tell you more. The significance of the command-line arguments and the behavior of the program in general are not conveyed by the name you provided. In particular, the fact that some of the arguments correspond to file names you recognize with their suffixes removed is probably meaningful, but we cannot tell you the meaning.

Additionally, you observe that

when I use the command line to check what shell is used it says tcsh

Undoubtedly you have checked what your own default shell is. That is not indicative of what shell R will use to run the command.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • Thank you, that definitely helps me understand better what's going on; and what I can look at to figure things out :) – Ryan S Feb 09 '21 at 16:38