Tag Info

New answers tagged

4

The argument to -c must be a single word, so su administrador -c "$OPENP_DIR/ctlscript.sh start" For "restart", you should "stop" first, then "start"


2

You can also use top instead of watch: top -p $(ps ax | grep python | awk '{print $1}' | paste -sd "," -) -d 2


5

You can watch any command so give this a try watch "ps aux | grep python"


1

I implemented a small script in Ruby to solve this problem. It's used like this: source | myscript.rb | sink Here's the source $stdout.sync # no outbound buffering by Ruby buf='' $stdin.each_char do |c| if buf.length>0 || c=='<' # buffering starts when '<' received buf << c ...


0

Just use sed. sed -i -re 's,(always @ \(posedge clock) [^)]*,\1,' source.v or, sed -i -re 's,(always @ \(posedge clock) ,\1) //,' source.v


0

At least GNU sed handles input that doesn't have a newline at the end (and it produces output without a final newline if the last incomplete line is passed through). A text file under Unix must by definition end with a newline if it isn't empty, and sed is a text utility, so this leniency to non-text input is not guaranteed. Since sed is designed to ...


2

Actually, thinking about it, you can first affect all possibles: source | tr '\n<' '<\n' | paste -sd\\n - -| sed -e'/^[0-9]\{1,\}>/!{$!H;1h;$!d'\ -e\} -e'x;y/\n</<\n/;s//<&/' | filter ... | sink That will break your in-stream by first unconditionally swapping all < for \n and afterward conditionally swapping them back ...


1

When a program writes to a terminal the buffer is flushed on every newline, but you can use the program unbuffer (Note in some distributions the command is stdbuf ) Try something like this unbuffer source | sed -e 's:xxxxx:yyyyy:g' | sink


0

Other way to escape double-quotes (and other special simbols) put all line(s) in single qoutes (if it is absent in your text): sed "s/^\|$/'/g" <sampleMetadata


2

With standard tools chest, sed is a good one: sed -e 's/"/\\&/g' <sampleMetadata


3

In your link, the variable used outside (linecount) is not defined as a "loop" variable. It's just modified (incremented) inside the body loop, but not in the "while" statement. This is because when the "read -r f1 f2..." part is called, it reset (prepare) the variables used (f1 ..f7), wait for an input line and assign the variables according to the input. ...


0

File does not need to be wiped of you insert one line afterwards, just insert the line with ">". @terdon something with xargs or parallel would work too: http://stackoverflow.com/questions/845863/how-to-use-in-an-xargs-command I'm fine with this comment-answer getting merged into yours :)


4

POSIX command/process substitution _log()( x=0 while [ -e "${TMPDIR:=/tmp}/$$.$((x+=1))" ] do continue; done && mkfifo -- "$TMPDIR/$$.$x" && printf %s\\n "$TMPDIR/$$.$x" || exit exec >&- >/dev/null { rm -- "$TMPDIR/$$.$x" logger --priority user."$1" --tag "${0##*/}" } ...


5

There's no POSIX equivalent. You can only perform a redirection with exec, not a fork. A pipe requires a fork, and the shell waits for the child to finish. One solution is to put all your code in a function. all_my_code () { … } { all_my_code | logger --priority user.notice --tag "$(basename "$0")"; } 2>&1 | logger --priority user.error --tag ...


2

There are two common approaches for this: find and shell globbing. find has an -exec option which lets you specify an action to be performed on each of its results. It makes each of find's results available as {} and you can modify them as you wish. It's slightly more complicated when you want to give arguments (such as echo foo > file). For that, you ...


2

Given the following tree (empty abc.txt): . ├── zyz │   └── abc.txt ├── zyz-1 │   └── abc.txt └── zyz-2 └── abc.txt You can list all the abc files with: $ echo zyz*/abc.txt zyz-1/abc.txt zyz-2/abc.txt zyz/abc.txt And you can use tee -a to append some input stream to all of those files at the same time: $ echo 'New line data' | tee -a ...


0

You are not giving any argument (filename) to stat leading to that error. You are using variable file to store the each filename and loop over them but you are not giving the filenames as arguments to stat. In a nutshell you need to pass $file (the value of variable file) to stat. Also you can do all you are doing in one line : for file in .* *; do stat ...


1

A pipe, just like any file, is a stream of text (more precisely, a stream of bytes). The basic building blocks of Unix tend to be simple. Interactions between processes are mostly based on unstructured data. The operating system doesn't provide a communication channel with multiple streams labeled by a file name. If programs need this, they need to arrange ...


2

I suspect that you're looking for set -o notify, available in ksh, bash, zsh, and even POSIX sh, which causes job completion notifications to be printed immediately, even if you're at typing a prompt or if some other job is in the foreground. (If that's not what you're looking for, please clarify your question, maybe with an example of how it would look ...


1

Try changing an environment variable - that will not work either. System inherits the environment and the current working directory. So each system call will inherit the current working directory from its parent.


0

You can create a shell function : myjobwatch() { while true; do jobs; sleep 2; clear; done; } Then just execute myjobwatch


1

Are you talking about program1 file1.txt | program2 | program3 > folder/file1.txt program1 file2.txt | program2 | program3 > folder/file2.txt program1 file42.txt | program2 | program3 > folder/file42.txt program1 green.txt | program2 | program3 > folder/green.txt program1 indigo.txt | program2 | program3 > folder/indigo.txt program1 ...


0

For viewing diff output in color, use colordiff. sudo apt-get install colordiff Pipe any diff-format output into colordiff: This includes some of diff's alternate formats, like -y (side-by-side.) Alternatively, if invoked standalone (without anything piped into it) then it acts as a wrapper around 'diff', and colors the output. Hence I have this in my ...


0

A great general-purpose Python tool for coloring the output of commands is 'colout' You give it a regex with N groups, followed by a comma separated list of N colors. Any text that matches a group will be displayed in the corresponding color. So for example, if you're looking at some test output: python -m unittest discover -v then you can spruce it ...


2

If you're stuck on Bash 3: echo {375..3500} | tr ' ' '\n' | sed -n 'p;n;n;n;n' and if you prefer awk: echo {375..3500} | tr ' ' '\n' | awk '!((NR-1)%5)' I didn't know about brace expansion -- that is seriously cool.


1

It looks like you are using a weird shell in your mingw environment - and not bash. Or a weird version of egrep. You can work around this via replacing those egrep shell calls with GNU make conditionals, e.g.: ifeq (,$(filter %686 %x86 %i86 %amd64,$(MACHINE))) IS_X86 = 0 else IS_X86 = 1 endif Alternatively, you could create something based on ...


2

Referring to 3.4.2 Special Parameters from Bash Reference Manual. Special Parameters: $* ($*) Expands to the positional parameters, starting from one. When the expansion is not within double quotes, each positional parameter expands to a separate word. In contexts where it is performed, those words are subject to further word splitting and pathname ...


1

Yes. man su | sed '/^FILES/,/^$/!d' FILES /etc/pam.d/su default PAM configuration file /etc/pam.d/su-l PAM configuration file if --login is specified /etc/default/su command specific logindef config file /etc/login.defs global logindef config file There's no sudoers there. Maybe these files have been configured in a ...


1

A free account at SageMath Cloud may fit your purpose. My account allows me to upload/download programs and compile/run them on a Ubuntu box located in the USA. The purpose of SageMath.org is to provide free, open source math software. The website is based on Python, but Python is not the only programming language available. In particular, an interactive ...


7

To answer your question directly: no, there is no good reason to do this. Also, sudo su produces two log entries when one would suffice. I've seen many people do this, and when I ask why they don't just run sudo -s, the answer is just that they don't know about the -s flag to sudo, and generally they switch after I point it out. However, to your list of ...


4

Google Compute Engine allows you to provision a Linux VM in your chosen region which you can then ssh into with root privileges. It's cheap and you can get $300 worth of usage as a free trial.


19

As you stated in your question, the main difference is the environment. sudo su - vs. sudo -i In case of sudo su - it is a login shell, so /etc/profile, .profile and .bashrc are executed and you will find yourself in root's home directory with root's environment. sudo -i is nearly the same as sudo su - The -i (simulate initial login) option runs the shell ...


2

You need more quoting when you pass arguments to SSH. Try this: ssh localhost "df -k / | awk '{print \$3/1024/1024/1024}'" 0 0.00623375 Note the \ before $3.


2

The Solaris 10 and earlier /bin/sh does not support $(). It is still in use today because Solaris 10 is still in use, Sun did not want to replace it with a standard conforming version (up to and including Solaris 10) - and because most people consider /bin/sh as the default shell and don't know how to portability execute a script with a POSIX conforming ...


0

You can't use and alias for this problem, because an alias can't take arguments in the middle, only at the end. You need a function for that. The following function does what you are asking for: cdd() { cd `find . -type d -name "$1"|head -n1` } You will have to add these lines to your .profile (or .bashrc file), so it is executed (once) when you log ...


3

The original Bourne shell, csh or tcsh all do not support $() and require `` for command substitution. The Bourne shell is no longer used as the default shell (/bin/sh) on many UNIX based operating systems. However, theses shells are still supplied by the OS vendors as they are still used for historical reasons. Both AIX and HP-UX have /bin/sh as a POSIX ...


0

Maybe with bash's recursive wildcard feature: shopt -s globstar # in ~/.bashrc, or just in cdd () {} cd **/structure/ I think ** expansion will happen in more or less the same order as find, and thus have most of the same problems. But it's so easy and useful that you may be able to overlook this!


4

POSIXly: i=370 while [ 3500 -gt "$i" ] do echo "$((i+=5))" done ...or... echo 'for(x=370;x<=3500;x+=5)x' |bc I dunno why you'd do it any other way. Excepting, of course... seq 375 5 3500 ...or with dc: echo '370[5+pd3500>p]splpx'|dc


1

Shell functions imitate subprocesses; like subprocesses, their return value is only an 8-bit number, conventionally indicating success (0) or failure (nonzero). To pass data out of a function, store it in a variable. Variables are not local to a function unless declared to be so. decrypt () { … valoare="$decrypt1" } … decrypt decrypted="$valoare" ...


1

What you're doing here is including second.sh and third.sh as sub-scripts running in the same process, which is called “sourcing” in shell programming. . ./second.sh is basically equivalent to including the text of second.sh at that point. The exit command exits the process, it doesn't matter whether you call it in the original script or in a sourced script. ...


11

Your for-loop snippet didn't work as you require for two reasons: (($i += 5)) - here the $i is expanded to the value of i. Thus the expansion will be something like ((375 += 5)), which doesn't make sense (attempting to assign a literal number to another literal number). This would normally be achieved with ((i += 5)) (no $ to expand the variable) The ...


5

While there is, of course, an app for that (seq 375 5 3500), there are various ways of doing this from the commandline. While the fastest and simplest will be just using seq, here are some other options: for i in {375..3500}; do [[ (($i % 5)) -eq 0 ]] && echo $i; done i=370; while [ $i -le 3500 ]; do printf "%s\n" $((i+=5)); done perl -le ...


3

zsh do not read .zshrc in non-interactive shell, but zsh allow you to invoke an interactive shell to run a script: $ zsh -ic 'type f' f is a shell function or you can always source .zshrc manually: $ zsh -c '. ~/.zshrc; type f' f is a shell function


4

You can use the DEBUG trap to do this. In this trap, $BASH_COMMAND contains the command last executed. trap 'echo "you tried to call the command [$BASH_COMMAND]"' DEBUG Note that, if you are executing commands as part of your prompt or $PROMPT_COMMAND, the trap will run on these as well. You can add checks to see if $BASH_COMMAND is the same as ...


24

Since you use brace expansion anyway so make use of its feature fully: echo {375..3500..5} To print each number in separate line with optional text: printf "Number %s is generated.\n" {375..3500..5} Number 375 is generated. Number 380 is generated. Number 385 is generated. ... Edit As pointed out by @kojiro in the comment Mac OS uses bash 3 as the ...


3

exec bash should replace the current shell process with (a new instance of) bash.


18

Alternatively a traditional C-style for loop can be used: for ((i=375; i<=3500; i+=5)); do echo $i done This is perhaps less clear than using seq, but it doesn't spawn any subprocesses. Though since I'm familiar with C, I wouldn't have any difficulty understanding this, but YMMV.


15

Using SEQ(1) for i in $(seq 375 5 3500) do echo $i done Or, simply: seq 375 5 3500


2

Most probably you have hidden files in the folder. The point is that glob * selects only files and folders that do not start with .. So, if they do they are not passed to du command. On the other hand from top directory you get size of the directory as a whole, including dot files. To match all files in given folder, including hidden ones try (with bash) ...


1

If I understood correctly, you want to get the last line of the file along with the line count: $ cat a aaa bb ccc $ $ awk 'END{print $0; print NR}' a ccc 3 Since you need them to save in variables: $ out=$(awk 'END{print $0"|"NR}' a) $ last_line=$(echo $out | awk -F"|" '{print $1}' ) $ tot_cnt=$(echo $out | awk -F"|" '{print $2}' ) $ echo $last_line ccc ...



Top 50 recent answers are included