Bash or tsch command without file extensions [closed] - bash

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
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.

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.

Related

bash/zsh - current directory (dot `.` ) command with file argument in rc file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I'm having difficulty finding information on what the following command is called or does? This command is meant to be called from .rc files.
What is this syntax called in bash and zsh? I know it's for both, as shell file is meant for both. What does it do when placed inside a file? What does it do in file/function/cli?
And what is the equivalent in fish (Friendly Interactive SHell)? Will the same bash/zsh shell file work with that equivalent command in config.fish?
> . /path/to/sh-file.sh # what does this do? nothing happens on cli when called.
> cat /path/to/sh-file.sh
[ -d "${_DATA:-$HOME/.kdcd}" ] && { echo ... }
_kd () {
....
}
This . does not refer to the current working directory as it usually does elsewhere. Rather, it is the short (and, it seems, the original) version of the source command, which executes the file specified in the current shell (even if it is not executable), rather than in a child shell, which is what happens when you run with ./file or bash file. Functions defined, variables assigned, and modifications to the environment made in child shells are unknown to the parent shell, so if you want a file to do something to the current shell, you probably want to source it.
$ type .
. is a shell builtin
$ help .
.: . filename [arguments]
Execute commands from a file in the current shell.
A common use of the source or . commands is to be able to immediately use aliases or functions defined in a particular file. For example, after making changes to a shell rc file, to use the new configuration immediately, one may run . .bashrc (or . .zshrc, etc).
It is also common for one file to source another as you saw. For example, as a shell's rc file is executed automatically in every interactive shell of that type when it starts, you can incorporate configurations in other files in every interactive shell you run by having the rc file source those files.
Both . and source work in the same way in the fish shell, but, of course, the syntax of the functions etc in the file you source may be incompatible with shells other than the one they were written for.

What does touch * do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I was asked a question in an interview recently - How you will delete a file named '*'?
So I tried creating a file as - touch *. When I list, I don't see this file. When I edit (vi *). I opens up a file with random text.
So what is touch *?
You should look up unix "globbing".
The shell will look at the command and replace * with every file (not starting with '.' or hidden) unless you escape this special character * just or put it in single quotes '*'
You can use this to apply a command to many files without actually listing them manually.
If you want to see what * expands and how you can escape it to you can run the following commands:
echo *
echo '*'
echo \*
You can also use this with more specific pattern like
<command> a* # run the command on the list of file starting with a
If you want to see what the terminal actually executed when you ran touch * run:
echo touch *
The touch command as others have explained before will either create a empty file if the filename does not exist, or update the last modified timestamp on existing files. So you just updated the last modified timestamps of every non hidden file in the directory you executed the command in.
Note that this happens before your command is ever called. And if the list of file is VERY large (millions) you will get an error as the list of files will be too large to fit into the command buffer (aka the string of your expanded command will be too large)
Further reading : https://www.linuxjournal.com/content/bash-extended-globbing
Shells expand *. touch * is touch every nonhidden file in the current directory. If you want to create a file literally named *, you need to quote it: touch \* (or touch '*' or touch "*" and the equivalent for other commands such as rm).
According to the man touch, touch changes a timestamp of a file. If the file doesn't exist, it creates it empty, unless -c or -h parameters are given.
In Bash, * is a globbing character which expands to every non-hidden file and directory in the current directory. That means touch * will change the timestamp of every file and directory in the current directory, if there is any, to the current date and time.

How to pass arguments to /bin/bash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Improve this question
In my terminal, I do
$ myprogram myfile.ext.
I want to be able to do the same via the command /bin/bash, but it is not working.
I tried
$ /bin/bash -c -l myprogram myfile.ext
but it is not working. It seems that my program is launched but without my file.ext as an option (as an input file)
Does anyone has a clue on how to do that?
Why I ask this question
I want to launch myprogram via NSTask in an a program I am writing for OSX, with the cocoa framework. If I simply ask NSTask to launch my program, it seems that some variable environment are missing. So, what I try is to launch a shell and inside this shell to launch myprogram.
Drop the -c altogether. From the manpage:
bash [options] [file]
…
Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file.
Thus, you can execute your program via
bash myprogram myfile.ext
and myfile.ext will be the first positional parameter.
bash -l myprogram myfile.ext
will work as well, (but whether or not bash is invoked as a login shell seems tangential to this question.)
-c string
If the -c option is present, then commands are read from
string. If there are arguments after the string, they are
assigned to the positional parameters, starting with $0.
You need to quote the command passed in as string so it's treated as a single argument for the -c option, which then gets executed normally with the argument following the command, i.e.
/bin/bash -c -l 'myprogram myfile.ext'

why doesn't me script take the last updated input file when running in unix bash? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an input file and a script running in unix bash.
the problem is every time i edit the input file in vi , the script takes the input file as it was inputed the first time.
How can i fix this ?
run
cat inputFile
to make sure it looks correct before passing it to your script. Try doing :wq! To make sure it will save the file even if the read only perms are set on the file. The "!" after wq will force a write despite permissions on the file.
Try typing ls -ltr inputFile and check the perms. If they look like below this then run chmod a+w inputFile
-r-r-r--
Use :w in vi to save your input file before executing the script.
Pure speculation, since many details are missing, but if your script opens the file and keeps it open, it will not see updates. If there is only one (hard) link to the file, then vi (assuming vi is actually vim, although I suspect most editors behave this way) will create a new file and change the link to it, but the script still has the original file open. A simple technique that might work is to create a second link to the file before you run the script:
$ ln input-file foo # Create a second link
$ script input-file # Run the script
$ vi input-file # Edit the file
This causes vim to modify its behavior so that it actually updates the file rather than creating a new one.
#user2613272: its either that you have not saved the file before executing it or you are executing some other file with similar name.
as suggested by #bjackfly, i guess you first "cat" your file before execution.

tab-expansion and "./" bash shell [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Maybe someone here would be able to help me out. Have installed Ubuntu 12.04 LTS (kubuntu) on two machines. The .bashrc and .bash_profile files are identical as the file structures on each machine is the same.
On machine 1: I run bash scripts within a terminal window with the simple: ./scriptname.sh
On machine 2: I cannot do this and must use: sh scriptname.sh
Nor can I use ./ and tab-complete the script filename.
All executable bits are set correctly, all files and folders have the correct permissions. In the header of the scripts the shebang is set correctly.
Any ideas why this would be occurring?
If I try to execute the script with ./file_motion_grab.sh:
bash: ./file_motion_grab.sh: Permission denied
When I try ls -l, I get:
-rwxrwxrwx 1 adelie adelie 351 Nov 4 20:32 file_motion_grab.sh
Output of getfacl is:
# file: file_motion_grab.sh
# owner: adelie
# group: adelie
user::rwx
group::rwx
other::rwx
More general - any new script on the second machine must be invoked with: sh scriptname.sh Something probably wrong in the .bash files. But not sure where to look.
I would recommend trying ls -al to check the permissions on the file and the directory. Also, try getfacl file.sh, because sometimes there are ACL permissions that override the normal Unix permission bits.
Then I would try head -n 1 file.sh | xxd, to look at the first line, and make sure the shebang is there properly as the first two characters of the file. Sometimes, hidden characters, like a Unicode BOM, can cause it not to be interpreted properly.
Then I would check the permissions on the shell itself. ls -l /bin/bash and getfacl /bin/bash. I would also check to see if this happens with other interpreters; can you use #!/bin/sh for a script? #!/bin/python (or Perl, or Ruby, or something of the sort)? Distinguishing whether this happens only for /bin/bash or for other shells would be helpful.
Also, take a look at ls /proc/sys/fs/binfmt_misc to see if you have any binary formats configured that might interfere with normal interpretation of a shell script.
Try testing from another account as well (if you can). Is the problem unique to your account? I would also try rebooting, in case there is just some transient corruption that is causing a problem (again, if you can).
(answer was originally a series of comments)

Resources