Run a built-in shell function in a script read with chat

#!/usr/bin/env bash function foo(){ param=$1 echo "$param" } content="calling this one with param: $(foo 'this is test param1')" echo "$content" result: calling this one with param: this is test param1 Notice that foo is call

Write two exit loops in two columns in the shell?

How can I write the following in an efficient way: for j in {1..339};do for i in {1..427};do echo -e $j'\t'$i >> ofile.txt done done here is one alternative without explicit loops join -j9 -t$'\t' <(seq 339) <(seq 427) | cut -f2- > ofile.tx

Portable method for resolving hostname to IP address

I need to resolve a host name to an IP address in a shell script. The code must work at least in Cygwin, Ubuntu and OpenWrt(busybox). It can be assumed that each host will have only one IP address. Example: input google.com output 216.58.209.46 EDIT:

Bash - Exclude subdirectories with the find command

This question already has an answer here: How to exclude a directory in find . command 29 answers I'm using the find command to get a list of folders where certain files are located. But because of a permission denied error for certain subdirectories

How to move some lines to the top of the file?

I have a file like this: aaa.bbb.1.ccc xxx.bbb.21 mmm.ppp xxx.eee mmm.qqqq xxx.hhh.12.ddd I want to move all the lines starting with xxx. at the top of the file with a simple command (using sed, awk, grep...). So my new file will look like this: xxx.

Pipe and process management

I am working on a tiny shell(tsh) implemented in C(it's an assignment). One part of assignment belongs to PIPING. I have to pipe a command's output to another command. e.g:ls -l | sort When I run the shell, every command that I execute on it, is proc

Unexpected release of Shell Unix script

I have this KornShell (ksh) script. It is printing only a and b. I am not sure why it is printing only these two letter? script: #!/bin/ksh for i in [global] do echo $i done exit 0 output: ./a.sh a b I need to understand how shell interpreting [globa

Analyze the JSON array: 'paste' for bash variables?

At first, I parsed an array JSON file with a loop using jshon, but it takes too long. To speed things up, I thought I could return every value of id from every index, repeat with word another type, put these into variables, and finally join them toge

Run multiple commands without using; and & amp;

I need to run a command ls and cal in single line But i need to write it without using & and ; symbols... Is there any way to write it?You could use backticks and echo echo `ls` "`cal`" The double quotes keep echo from destroying the whitesp

Where to put shell script / function? .bashrc or bin?

I am learning Linux commands and I learnt that you can write a shell script and put in a customized directory (e.g. ~/bin/ ) and export to $PATH or you can write it as a shell function and put in .bashrc file. If I may ask, what is the right situatio

Shell script for monitoring CPU load

I am looking for a script which does monitor the cpu usage per day. All the scripts that I have come across does kind of real time monitoring and send an email if it meets certain aspects like the load increasing beyond 80%. Is it possible to monitor

Save the output of the time command in a log file

I have a script hex.bat that has: #!/bin/bash HEX_ROOT=. HEX_COLOURS=./data HEX_PDB=. HEX_MACROS=. HEX_CACHE=./data time ./hex6i.x64 -kill -nogui -ncpu 1 -ngpu 1 -e dock.mac -l job.log All the output goes to job.log, except the time. I want to save i

How to get a return value from a Java class on UNIX

Please suggest a way to get the return String from my class in UNIX. This is my sample class: package com.mytest.package.main; public class DateExtractor { public static String getDate() { return "20120924"; } public static void main (String[] a

search the output line and save in variable

How to search word of the output of a shell script and save in other variable . Below command will display the list of baselines in my view . cmd :cleartool lsstream -fmt "%[found_bls]NXp\n" -view $VIEW_NAME Output : baseline:MHC_BUILDTREE1.0.1

How do i say what kind my shell is

How can I tell what type my shell is? ie, whether it's traditional sh, bash, ksh, csh, zsh etc. Note that checking $SHELL or $0 won't work because $SHELL isn't set by all shells, so if you start in one shell and then start a different one you may sti

Shell: Nested for the loop

Somehow in the following script, value of $i is not expanded on line 3. Any idea why? for i in `cat test.txt` do for j in `find . -name $i` do echo $j done done for i in `cat test.txt | sed -e "s/\r//g"`; do find -name $i; done big question: cyg

Open a Cygwin file

Is there an equivalent to OSX open command in cygwin. open opens a file with the default application for that type. I want to do something like $ magic-command file.xls #excel opens as if file.xls would have been double-clicked $ magic-command file.t