How do I read a row of data and assign them to variables while also giving them default values? I wanted to achieve something like this, but can't get the syntax right. { read variable1=${variable1:=default1} variable2=${variable2:=default2} read var
I want to run a set of commands out of which some I want to run simultaneously in another terminal using shelll script. Let's say I have the below four commands command1 command2 command3 command4 First I want to start command1 in terminal 1 & while
#!/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
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
I wrote following Go code. package main import ( "fmt" "os" "strings" ) func main() { fmt.Println(os.Args) } Then compiled it... $ go build -o out And created following script a.sh: #! /bin/bash set -eu ./out "--opt1&quo
loopcount=1 loopmax=5 while [ $loopcount -le $loopmax ] do echo "loop iteration :$loopcount" ((loopcount=loopcount+1)) done for this i am getting o/p like this loop iteration :1 loop iteration :2 loop iteration :3 loop iteration :4 loop iteratio
somethingsame,somethingsame_usage,2015-11-30 01:00:00,0 somethingsame,somethingsame_usage,2015-11-30 02:00:00,0 somethingsame,somethingsame_usage,2015-11-30 03:00:00,0 somethingelse,somethingelse_usage,2015-11-30 01:00:00,0 somethingelse,somethingels
I have to write a bash script that launches a process in background in accordance to command line argument passed and returns if it were successfully able to run launch the program. Here is a pseudo code of what I am trying to achieve if [ "$1"
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:
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
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.
Using
[email protected] inside a bash test expression gives odd results. Here's a minimal test script to reproduce the issue (among the alternative formulations for the same test which do pass without error): #! /bin/bash # file path: ./bash_weirdness.sh echo "args
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
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
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
I am trying to redirect the output but I have 2 issues. Issue 1: ls -l > file works fine, but if I do cat file1 > file2, my shell seems to be working indefinitely in the background. I have to interrupt it (Ctrl-D) after 2 to 3 min of wait. issue 2:
I'm working on a unix script that has 2 input parameters - path and size. The script will check all the files in the given path with the given size and deletes them. If the delete operation fails, the respective file-name is recorded into a file. For
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
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
I want to perform some commands on Intersystem cache from shell script. One solution which I know is through making a config file but the problem is I dont know how to use config file through shell script. Is there any other solution for this... for
There is a file post_check.ini I need the value set for: Max_value=2 How would I get the value 2 from Max_value?try grep -Po '(?<=Max_value=).*' post_check.ini
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
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
I have a text file, it contains a single word on each line. I need a loop in bash to read each line, then perform a command each time it reads a line, using the input from that line as part of the command. I am just not sure of the proper syntax to d
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
When I want to grep all the html files in some directory, I do the following grep --include="*.html" pattern -R /some/path which works well. The problem is how to grep all the html,htm,php files in some directory? From this Use grep --exclude/--
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 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
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
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