Hello i was able to run one of the script from putty terminal without any issue as follows
sh file_validation_generic.sh 1 /test/data/infa_shared/dev/scripts
but when i try to execute the script from a tool it is giving below error
sh -c "ksh /test/data/infa_shared/dev/scripts/file_validation_generic.sh 1 /test/data/infa_shared/dev/scripts"
error :-
/test/data/infa_shared/dev/scripts/file_validation_generic.sh[121]: read: -a: unknown option
Usage: read [-ACprsSv] [-d delim] [-u fd] [-t timeout] [-n count] [-N count]
[var?prompt] [var ...]
this error occurs in a while loop during the read to an array
IFS="~"
read -a star <<< "$line"
col_pos=${star[1]}
col_patt=${star[6]}
Related
I am working on a HPC running slurm and CentOS. My workflow software (Nextflow v19.10.0) needs to execute this command
squeue --noheader -o %i %t -t all -u username
However, I have an error raises the following error
squeue: error: Unrecognized option: %
Usage: squeue [-A account] [--clusters names] [-i seconds] [--job jobid] [-n name] [-o format] [-p partitions] [--qos qos] [--reservation reservation] [--sort fields] [--start] [--step step_id] [-t states] [-u user_name] [--usage] [-L licenses] [-w nodes] [--federation] [--local] [--sibling] [-ahjlrsv]
Is there a way to wrap the above command in my .bashrc file, so when ever Nextflow runs the command it would automatically turned into this, which I have tested to work on my cluster?
squeue --noheader -o "%i %t" -t all -u username
Thanks so much for your help!!!
If Nextflow is running bash (the shell you tagged this question for), not /bin/sh (which is more common, as it's what the system() library call in many languages invokes), you can do this in any enclosing shell:
# override *any* call to squeue with a very specific command that's known to work
squeue() {
printf 'Ignoring old squeue arguments: ' >&2
printf '%q ' "$#" >&2
printf '\n' >&2
command squeue --noheader -o '%i %t' -t all -u username
}
export -f squeue
However, that probably won't work: It's likely that Nextflow is actually using sh instead, so instead of using an exported function, you'll want to create a directory with a squeue executable script in it that then invokes the real squeue command. Thus:
#!/bin/bash
printf 'Ignoring old squeue arguments: ' >&2
printf '%q ' "$#" >&2
printf '\n' >&2
# FIXME: replace /usr/bin/squeue with the actual location of the real command
exec /usr/bin/squeue --noheader -o '%i %t' -t all -u username
i'm using embedded linux here i need to set the current date to system which is based on user input given by the key board,here i'm failing at one condition that is the system has to wait for 2 minutes un till gets input from keyboard if it reaches to specified wait time it has to come out from loop.......
Below is my piece of code:
echo please enter the date in below format
echo YEAR- MM-DD HRS:MNS:SEC and press enter
read -e a1
startd=$(date -s "$a1");
echo "$startd";
hwclock --systohc
date
You should use option -t in your the read command:
if read -e -t 120 a1; then
echo "input: $a1"
else
echo "no input"
fi
From the bash man page:
read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
...
-t timeout
Cause read to time out and return failure if a complete line of input (or a specified number of characters) is not read within timeout seconds.
I have a pretty simple bash script that sends command to serial and reads thee value back. The problem is when I don't get a value back,, it can get stuck.
echo BC > /dev/ttyS1
read line < /dev/ttyS1
echo $line
I have used the cat command with a timeout, but cannot use the same technique with 'read', because if I send the process to the background, I never get value back on exit. 'cat' works for the most part, but i'm not sure if this is the most robust way to do this.
echo BC > /dev/ttyS1
cat /dev/ttyS1 &
pid=$!
sleep 0.1
kill -9 $pid
From section 4.2 Bash Builtin Commands of the Bash Reference Manual:
read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name …]
...
-t timeout
Cause read to time out and return failure if a complete line of input is not read within timeout seconds. timeout may be a decimal number with a fractional portion following the decimal point. This option is only effective if read is reading input from a terminal, pipe, or other special file; it has no effect when reading from regular files. If timeout is 0, read returns success if input is available on the specified file descriptor, failure otherwise. The exit status is greater than 128 if the timeout is exceeded.
I'm trying to understand how programs, shell commands and operating
systems work. Please excuse my ignorance since I'm new to this.
When I use a C compiler on the command line, when I type cc
[filename] , I suppose the shell uses a fork() system call to
duplicate its process and then an exec() system call will load the
cc compiler executable into the child process' core image. Then the
child process containing the cc executable will do its thing while
the parent process executing the shell waits, or not. Is it right?
What about shell commands like cp, mv, ls, and others. What are they?
are they executable programs that will also be executed in a new
child process forked by the shell?
What about shell scripts? Suppose I create a simple shell script
like this one (please ignore any errors I dont know how to do this
yet) :
echo "Hello"
date
echo
cc -o test file1.c file2.c file3.c
and then I execute this script using the command line. Will the
command line fork() a new process and exec() this script in the new
process? And then will this new process containing the script fork()
other processes to execute date, cc compiler, etc ??
I hope this doesn't sound too confusing, because I am =/.
Yep! You've got the idea.
When I use a C compiler on the command line, when I type cc [filename] , I suppose the shell uses a fork() system call to duplicate its process and then an exec() system call will load the cc compiler executable into the child process' core image. Then the child process containing the cc executable will do its thing while the parent process executing the shell waits, or not. Is it right?
That's right. The parent process (the shell) calls wait() on the child's PID and waits for it to exit.
What about shell commands like cp, mv, ls, and others. What are they? are they executable programs that will also be executed in a new child process forked by the shell?
Same thing. These are binaries just like a compiler, and the shell does the same thing for them.
Now there are some commands which aren't external binaries known as "built-ins". These are commands that the shell recognizes itself and doesn't need to call an external binary for. Why?
Some have special syntax, like if and while, and so by necessity must be built into the shell.
Some, like cd and read, change the shell process's state, and so must be built-ins. (It's impossible for an external binary to change the shell's current directory since forked processes can only change their own PWD, not their parent's.)
Others, like echo and printf, could be separate binaries, and just happen to be implemented by the shell.
Here's a full list of bash builtins I got from typing help:
job_spec [&] history [-c] [-d offset] [n] or history -anrw [filename] or histor>
(( expression )) if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [>
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -x command [args]
: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill>
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callbac>
bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r k> popd [-n] [+N | -N]
break [n] printf [-v var] format [arguments]
builtin [shell-builtin [arg ...]] pushd [-n] [+N | -N | dir]
caller [expr] pwd [-LP]
case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars>
cd [-L|[-P [-e]]] [dir] readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callb>
command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] or readonly -p
compgen [-abcdefgjksuv] [-o option] [-A action] [-G globpat] [-W w> return [n]
complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] [-G gl> select NAME [in WORDS ... ;] do COMMANDS; done
compopt [-o|+o option] [-DE] [name ...] set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFgilrtux] [-p] [name[=value] ...] source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ...] test [expr]
echo [-neE] [arg ...] time [-p] pipeline
enable [-a] [-dnps] [-f filename] [name ...] times
eval [arg ...] trap [-lp] [[arg] signal_spec ...]
exec [-cl] [-a name] [command [arguments ...]] [redirection ...] true
exit [n] type [-afptP] name [name ...]
export [-fn] [name[=value] ...] or export -p typeset [-aAfFgilrtux] [-p] name[=value] ...
false ulimit [-SHacdefilmnpqrstuvx] [limit]
fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command] umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMANDS; done unset [-f] [-v] [name ...]
for (( exp1; exp2; exp3 )); do COMMANDS; done until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name () { COMMANDS ; } variables - Names and meanings of some shell variables
getopts optstring name [arg] wait [id]
hash [-lr] [-p pathname] [-dt] [name ...] while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }
Aside from built-ins there are also functions and aliases. These are ways of defining new functionality without having to create separate scripts/binaries.
uppercase() {
tr '[:lower:]' '[:upper:]' <<< "$*"
}
alias ls='ls --color=auto -F'
Functions and aliases are usually for convenience or to add supplementary functionality.
What about shell scripts? ... Will the command line fork() a new process and exec() this script in the new process? And then will this new process containing the script fork() other processes to execute date, cc compiler, etc ??
Yes, exactly right. When a shell script is run the parent shell forks a child process and the script runs there. The commands in the script and therefore forked off of this child process; they are grandchildren of the original shell.
When you execute a shellscript, it does fork off and create a new shell, interpreting each command through a separate fork/exec mechanism. However, there are some shell builtins, for example, echo may be built into some shells even when it is available as an executable in /usr/bin. cp and mv are indeed executables that are executed through fork/exec mechanism. One thing you may have missed is that the executables need to be in a directory contained in your PATH variable. Try renaming a hello world code executable in your current directory as ls and specify your current directory (.) as the first one in your path. You can also find out about the executables using type and which commands.
I inappropriately asked my question on 'How do I prompt for input in a Linux shell script?'
I've gone through the 'Questions with similar titles' list and cannot see an answer.
I obviously don't have bash4 as the following doesn't work:
$ read -e -p "Enter database SID, or just return for default: " -i "swmfolx" ORACLE_SID
-bash: read: -i: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]
'All' I am trying to do is prompt for input with the option of just return for the default.
Any links or advice would be gratefully acknowledged.
You'll need to do this as follows:
read -p "Enter database SID: " dbsid
if [ "$dbsid" = "" ]
then
dbsid="mydefaultvalue"
fi
...essentially, read the value and if all they've done is hit enter, it assigns the default value.