Tag Info

Hot answers tagged

17

Ctrl+4 sends ^\ Terminals send characters (or more precisely bytes), not keys. When a key that represents a printable character is pressed, the terminal sends that character to the application. Most function keys are encoded as escape sequences: sequences of characters that start with the character number 27. Some keychords of the form Ctrl+character, and a ...


17

First, note that $@ without quotes makes no sense and should not be used. $@ should only be used quoted ("$@") and in list contexts. for i in "$@" qualifies as a list context, but here, to loop over the positional parameters, the canonical, most portable and simpler form is: for i do something with "$i" done Now, to loop over the elements starting from ...


6

I think you want the shift builtin. It renames $2 to $1, $3 to $2, etc. Like this: shift for i in "$@"; do echo $i done


5

The command you ran created a symbolic link in the current directory. Judging by the prompt, the current directory is your home directory. Creating symbolic links to executable programs in your home directory is not particularly useful. When you type the name of a program, the shell looks for it in the directories listed in the PATH environment variable. To ...


4

In addition to Gilles answer let me add, that you can always input non-printable characters in bash with Ctrl-v+key (Ctrl-v+Ctrl+4 in this case) and check the character code with $ printf '^\' | od -An -tu # input ^\ as C-v C-4 28 you get the decimal code of the character, which as you may check in man ascii corresponds to file separator (FS).


4

zsh -o SOURCE_TRACE and some more words to get to at least 30 characters.


4

I'm not sure if I understand your question properly, but I believe you want to align the columns. If that is the case then the command column is handy: column -s, -t file Output: Thu Aug 27 2015 7:56:29 AM PoolName Total GB Used GB Available GB Percent Full Oracle-RAID10 6432.539 6179.295 253.244 ...


4

Many tools can be handy: -n of grep is exactly what you are looking for. grep -n 'bla' file alternatively awk: awk '/bla/{print NR":"$0}' file alternatively perl: perl -ne 'print $.,":",$_ if /bla/' file alternatively sed: sed '/bla/!d;=' file |sed 'N;s/\n/:/'


4

Well, the exact sequence may vary, as there might be a shell alias or function that first gets expanded/interpreted before the actual program gets executed, and then differences for a qualified filename (/usr/libexec/foo) versus something that will be looked for through all the directories of the PATH environment variable (just foo). Also, the details of the ...


3

Your variable syntax is wrong. A variable is quoted as ${n}. Hence, try sed -i -e "1,${n}d" filename


3

I could reproduce the phenomenon on Ubuntu 15.04 with the following crontab: * * * * * { echo job 0; } & sleep 5 * * * * * { echo job 1; } & * * * * * { sleep 5; echo job 2; } & I got mails from cron with job 0 every minute, mails with job 1 occasionally (5-6 times in last 10 minutes), no mails with job 2. So it seems cron waits for the child ...


3

Upon further testing, I suspect the & is messing with your results. As you point out, &>/dev/null is bash syntax, not sh syntax. As a result, sh is creating a subshell and backgrounding it. Sure, the subshell's echo creates stderr, but my theory is that: cron is not catching the subshell's stderr, and the backgrounding of the subshell always ...


2

With bash: for f in XYZ*/*; do mv -v "$f" "${f%/*}/${f:0:5}${f##*/}"; done The for loop runs trough all XYZ* directories. Then the mv command renames the files. Where: $f is the original filename ${f%/*} is the directory name ${f:0:5} is the prefix ${f##*/} is the original filename


2

With zsh: autoload zmv # best in ~/.zshrc zmv '(XYZ??)(*)/(*)' '$1$2/$1$3'


2

When the shell parses a command line, it removes quotes but remembers the text structure that they imply.  (That is a gross oversimplification; see bash(1) or Shell Command Language for more details.)  For example, the command-line input -blah apple -secondfruit "green banana" -some more causes the shell to identify six words, or tokens: -blah apple ...


2

If it must be with echo "Kate", use awk: echo "Kate" | awk 'NR==FNR{a=$0;next} sub("Steven", a, $0)1' - file The standard input is Kate from echo "Kate", piped to awk. awk then reads the stdin (-). The condition NR==FNR is true when the first file is processes (stdin). The variable a is set to that value. Then the input of file is processed and sub() ...


2

There's always the caveman approach: first=1 for i do if [ "$first" ] then first= continue fi something with "$i" done This leaves $@ intact (in case you want to use it later), and simply loops over every argument, but doesn't process the first one.


2

You have newlines because ls puts them on separate lines. The newlines disappear without the quotes because the shell (bash) passes each unquoted space separated text to the command as a separate argument. Note: The command substitution is done by the shell, not by ls, so you do not need ls. Therefore you can do #!/bin/bash echo *.fastq or ...


2

Line 4 of parent.sh, you wrote sh /child.sh & $f. The ampersand must be put at the end of the command like that: sh /child.sh $f &. In your case, you are trying to run sh /child.sh in background, and then you are executing $f in foreground, which will lead to a permission denied as I can assume that your files /vol4/commit/file[1-9] are not ...


1

When you use a hereis string <<END all $variable expansion is done. This is how your define lines can work. But you dont want the $lastMonth and so on in the WHERE statement to be expanded, so you need to quote them with backslash. The single quote has no particular effect here as we are inside a hereis. However, it seems that sqlplus uses ampersand ...


1

In bash you can also write that loop with explicit indexing: for ((i=2; i<=$#; ++i)); do process "${!i}" done This iterates over all arguments from the second one to the last one. If you want to exclude the last argument instead, simply make this for ((i=1; i<=$#-1; ++i)); do process "${!i}" done and if you only want to take every other ...


1

test -f won't work for multiple files expanded from wildcards. Instead you might well use a shell function with null-redirected ls. present() { ls "$@" >/dev/null 2>&1 } if [ $# -lt 1 ]; then echo "Please enter the path" exit fi path=$1 if ! present $path/cc*.csv && ! present $path/cc*.rpt && ! present ...


1

Assuming a textbook example shell (for code clarity) that is already running (so the dynamic linker is done), the commands you mention will require the shell to make the following system calls: read: gets the next command in this case gcc fork: two process are needed, we assume the parent has pid 500 and the child for illustration. the parent will call ...


1

When you refer to a variable without quotes around it (e.g. echo $files), the shell splits the value apart on whitespace and passes each term as a separate command-line option. Newlines are treated the same as any other whitespace. The echo program doesn't see the newline characters at all; it just gets an array of strings, each of which is a single ...


1

When referencing a variable, it is generally advisable to enclose its name in double quotes. This prevents reinterpretation of all special characters within the quoted string -- except $, ` (backquote), and \ (escape). Keeping $ as a special character within double quotes permits referencing a quoted variable ("$variable"), that is, replacing the variable ...


1

If I understand the question correctly, you want to rsync all the files in the range A0000000 through A0000095.  Well, then, don’t say A*; use a list of positive wildcards (a.k.a. globs or filename expansion patterns) that generate the file names you want, rather than identifying the ones you want to exclude.  Do it by decomposing the range into subranges: ...


1

You were almost there with your first attempt. The problem is that adb unhelpfully adds a carriage return at the end of every line. You can't see it in the basic usage where the output is printed to the terminal, because a carriage return at the end of a line has no visual effect (the carriage return moves the cursor to the beginning of the current line, but ...


1

Since /etc/rc.local is executed at the end of each multiuser runlevel, it's not the correct place to add start scripts. I recommend to not use /etc/rc.local in any way. It's a reclit for early *nix times. Instead of that, create a startup script in /etc/init.d/name which accepts start and stop arguments to start or stop the deamon, process or the job: #! ...


1

As you mentioned that it should be an automated shell script, at least for the two yum commands you would need to add -y so yum will assume an answer of "yes" for all questions it will ask. See the yum man page, relevant excerpt: -y, --assumeyes Assume yes; assume that the answer to any question which would be asked is yes. ...



Only top voted, non community-wiki answers of a minimum length are eligible