tagged [shell]

An example of how to use getopts in bash

An example of how to use getopts in bash I want to call `myscript` file in this way: or My requirements are: - `getopt`- `-s`- `-s`- `-p`- `./myscript -h``./myscript` I tried so far this code: ``` #!/...

2 Oct at 04:21

How can I compare numbers in Bash?

How can I compare numbers in Bash? I'm unable to get numeric comparisons working: The problem is that it compares the number from the first digit on, i.e., 9 is bigger than 10, but 1 is greater than 0...

25 Apr at 16:22

Given two directory trees, how can I find out which files differ by content?

Given two directory trees, how can I find out which files differ by content? If I want find the differences between two directory trees, I usually just execute: This outputs exactly what the differenc...

6 Apr at 12:37

Simulating ENTER keypress in bash script

Simulating ENTER keypress in bash script I've created a really simple bash script that runs a few commands. one of these commands needs user input during runtime. i.e it asks the user "do you want to ...

27 Dec at 15:23

How to run SQL in shell script

How to run SQL in shell script How do you run a SQL command in a shell script while setting a variable? I had tried this method and it isn't executing the command, it is thinking the command is just a...

4 Oct at 18:22

Escape dollar sign in string by shell script

Escape dollar sign in string by shell script Suppose I have a script named dd.sh, and I run it like this So `$1` is the string `sample$name.mp4`. Then how to process `$1` that I can detect whether the...

9 Jan at 16:15

Windows Kiosk App

Windows Kiosk App So, I need to build a kiosk type of application for use in an internet cafe. The app needs to load and display some options of things to do. One option is to launch IE to surf. Anoth...

27 Aug at 03:5

Running script upon login in mac OS X

Running script upon login in mac OS X I am wondering if anyone is able to help me out with getting a shell (.sh) program to automatically run whenever I log in to my account on my computer. I am runni...

Shell - Write variable contents to a file

Shell - Write variable contents to a file I would like to copy the contents of a variable (here called `var`) into a file. The name of the file is stored in another variable `destfile`. I'm having pro...

23 Jul at 19:40

How can I add a line to a file in a shell script?

How can I add a line to a file in a shell script? I want to add a row of headers to an existing CSV file, editing in place. How can I do this? and I want to end up with Changing the initial CSV output...

14 Dec at 16:28

How to remove all .svn directories from my application directories

How to remove all .svn directories from my application directories One of the missions of an export tool I have in my application, is to clean all `.svn` directories from my application directory tree...

3 Jul at 08:40

"unary operator expected" error in Bash if condition

"unary operator expected" error in Bash if condition This script is getting an error: ``` elif [ $operation = "man" ]; then if [ $aug1 = "add" ]; then #

14 May at 16:52

Get specific line from text file using just shell script

Get specific line from text file using just shell script I am trying to get a specific line from a text file. So far, online I have only seen stuff like sed, (I can only use the sh -not bash or sed or...

8 Sep at 08:37

How to check the exit status using an 'if' statement

How to check the exit status using an 'if' statement What would be the best way to check the in an `if` statement in order to echo a specific output? I'm thinking of it being: The issue I am also havi...

Running a script inside a docker container using shell script

Running a script inside a docker container using shell script I am trying to create a shell script for setting up a docker container. My script file looks like: Running this script file will run the c...

6 Jan at 12:20

How to mkdir only if a directory does not already exist?

How to mkdir only if a directory does not already exist? I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the `mkdir` command to create a directory. But the dir...

12 Sep at 15:48

Pipe output and capture exit status in Bash

Pipe output and capture exit status in Bash I want to execute a long running command in Bash, and both capture its exit status, and [tee](http://en.wikipedia.org/wiki/Tee_(command)) its output. So I d...

27 Aug at 04:9

How to count differences between two files on linux?

How to count differences between two files on linux? I need to work with large files and must find differences between two. And I don't need the different bits, but the number of differences. To find ...

4 Jan at 07:21

How can I remove the extension of a filename in a shell script?

How can I remove the extension of a filename in a shell script? What's wrong with the following code? As is, I get the literal string `$filename | cut -f1 -d'.'`, but if I remove the quotes I don't ge...

4 Apr at 22:25

How to perform grep operation on all files in a directory?

How to perform grep operation on all files in a directory? Working with xenserver, and I want to perform a command on each file that is in a directory, grepping some stuff out of the output of the com...

3 Dec at 20:28

How to send list of file in a folder to a txt file in Linux

How to send list of file in a folder to a txt file in Linux I'm fairly new to Linux (CentOS in this case). I have a folder with about 2000 files in it. I'd like to ideally execute a command at the com...

6 Nov at 06:37

Multi-line string with extra space (preserved indentation)

Multi-line string with extra space (preserved indentation) I want to write some pre-defined texts to a file with the following: I'm expecting something like this: But got this: ``` this is line one th...

25 May at 19:59

Unix - create path of folders and file

Unix - create path of folders and file I know you can do `mkdir` to create a directory and `touch` to create a file, but is there no way to do both operations in one go? i.e. if I want to do the below...

10 Feb at 18:34

How do I mount a remote Linux folder in Windows through SSH?

How do I mount a remote Linux folder in Windows through SSH? I'm a blind student currently in a system admin/shell programming class. Although ssh works fine for executing commands like ls, pwd, etc e...

14 Jan at 16:50

Using if elif fi in shell scripts

Using if elif fi in shell scripts I'm not sure how to do an `if` with multiple tests in shell. I'm having trouble writing this script: ``` echo "You have provided the following arguments $arg1 $arg2 $...

27 Apr at 11:57

In a unix shell, how to get yesterday's date into a variable?

In a unix shell, how to get yesterday's date into a variable? I've got a shell script which does the following to store the current day's date in a variable 'dt': How would i go about getting date int...

19 Aug at 02:12

Threaded wget - minimalizing resources

Threaded wget - minimalizing resources I have a script that is getting the GeoIP locations of various ips, this is run daily and I'm going to expect to have around ~50,000 ips to look up. I have a Geo...

15 Sep at 16:36

find: missing argument to -exec

find: missing argument to -exec I was helped out today with a command, but it doesn't seem to be working. This is the command: The shell returns ``` find: missing argument to `-exec' ``` What I am bas...

19 Jun at 03:59

How to kill all processes matching a name?

How to kill all processes matching a name? Say I want to kill every process containing the word amarok. I can print out the commands I want to execute. But how do I actually make the shell execute the...

18 Sep at 17:9

Make dependency generation using shell and %?

Make dependency generation using shell and %? I have a bunch of directories. I want to build an object for each directory. Suppose OBJS contains "build/dir1 build/dir2 build/dir3", and the pattern I'm...

4 Oct at 05:23

Display curl output in readable JSON format in Unix shell script

Display curl output in readable JSON format in Unix shell script In my Unix shell script, when I execute a curl command, the result will be displayed as below which I am redirecting to file: But, I wa...

9 Jul at 17:42

unix - count of columns in file

unix - count of columns in file Given a file with data like this (i.e. stores.dat file) What would be a command to output the number of column names? i.e. In the example above it would be 4. (number o...

20 Jul at 09:28

Run shell commands using C# and get the info into string

Run shell commands using C# and get the info into string I want to run a shell command from C# and use the returning information inside my program. So I already know that to run something from termina...

22 Oct at 05:1

How to force 'cp' to overwrite directory instead of creating another one inside?

How to force 'cp' to overwrite directory instead of creating another one inside? I'm trying to write a Bash script that will overwrite an existing directory. I have a directory `foo/` and I am trying ...

30 Jul at 20:50

Interactive shell using Docker Compose

Interactive shell using Docker Compose Is there any way to start an interactive shell in a container using Docker Compose only? I've tried something like this, in my docker-compose.yml: When I start t...

How to set the From email address for mailx command?

How to set the From email address for mailx command? I am working on a KornShell (ksh) script running on a Solaris server that will send out an email when and error condition is met. I am sending the ...

22 Aug at 10:41

Returning value from called function in a shell script

Returning value from called function in a shell script I want to return the value from a function called in a shell script. Perhaps I am missing the syntax. I tried using the global variables. But tha...

8 Aug at 21:3

ShellExecute equivalent in .NET

ShellExecute equivalent in .NET I'm looking for the .NET-preferred way of performing the same type of thing that ShellExecute does in Win32 (opening, printing, etc. for arbitrary file types). I've bee...

Expansion of variables inside single quotes in a command in Bash

Expansion of variables inside single quotes in a command in Bash I want to run a command from a which has single quotes and some other commands inside the single quotes and a variable. e.g. `repo fora...

16 Feb at 01:7

How to empty (clear) the logcat buffer in Android

How to empty (clear) the logcat buffer in Android How can I empty (clear) the logcat buffer in Android? I use adb logcat from command line and pipe the output to a file, since the DDMS has a very limi...

12 Jan at 13:6

"No such file or directory" but it exists

"No such file or directory" but it exists I simply want to run an executable from the command line, `./arm-mingw32ce-g++`, but then I get the error message, I'm running Ubuntu Linux 10.10. `ls -l` lis...

16 Oct at 14:0

Using jq to fetch key value from json output

Using jq to fetch key value from json output I have a file that looks as below: ``` { "repositories": [ { "id": "156c48fc-f208-43e8-a631-4d12deb89fa4", "namespace": "rhel12", "namespaceType": ...

30 Sep at 19:10

Get File Icon used by Shell

Get File Icon used by Shell In .Net (C# or VB: don't care), given a file path string, FileInfo struct, or FileSystemInfo struct for a real existing file, how can I determine the icon(s) used by the sh...

23 May at 12:26

How can I pass a file argument to my bash script using a Terminal command in Linux?

How can I pass a file argument to my bash script using a Terminal command in Linux? So my question is how can I pass a file argument to my bash script using a Terminal command in Linux? At the moment ...

20 Jun at 09:12

Check if an element is present in a Bash array

Check if an element is present in a Bash array I was wondering if there is an efficient way to check if an element is present within an array in Bash? I am looking for something similar to what I can ...

3 Jun at 20:27

How can I count all the lines of code in a directory recursively?

How can I count all the lines of code in a directory recursively? We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories. We don't need t...

7 Apr at 23:39

How can I strip first X characters from string using sed?

How can I strip first X characters from string using sed? I am writing shell script for embedded Linux in a small industrial box. I have a variable containing the text `pid: 1234` and I want to strip ...

22 Apr at 23:39

write a shell script to ssh to a remote machine and execute commands

write a shell script to ssh to a remote machine and execute commands I have two questions: 1. There are multiple remote linux machines, and I need to write a shell script which will execute the same s...

18 Dec at 07:15

How to use su command over adb shell?

How to use su command over adb shell? I need to make a script that executes a lots of thing on Android device, my device is rooted, when I enter on the shell, I can give the command su, and it works b...

3 Dec at 14:34

Unix shell file copy flattening folder structure

Unix shell file copy flattening folder structure On the UNIX bash shell (specifically Mac OS X Leopard) what would be the simplest way to copy every file having a specific extension from a folder hier...

26 Aug at 10:23