The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

4
votes
2answers
174 views

Run another command before running the command the user wants to run

Let's say I want to modify the original behavior of the ls tool this way: $ ls Hello World file1 file2 ... How can I do this? When running ls I would like to run another command let's say echo ...
1
vote
2answers
166 views

Why does “grep '.*[s]' file” work and “grep .*[s] file” doesn't?

Comparing grep '.*[s]' file with grep .*[s] file Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
11
votes
3answers
536 views

Terminal vs bash? [duplicate]

I'm on a Mac but I think this is generally Unix-applicable. I'm in the process of learning shell scripting and there's something I seem to be missing. When I'm in the ordinary terminal, I can use ...
0
votes
2answers
9 views

tcpdump filter expression breaks via adb

I installed tcpdump on my Android tablet and am running commands from a root adb shell. I'm working from the tcpdump man page examples, specifically this one: To print all IPv4 HTTP packets to and ...
1
vote
1answer
32 views

BASH: Command not running, special character '�' suddenly appeared (Ubuntu)

When I erroneously type 'ñ' (expecting to type any command) and then remove it and type the correct letter, the output returns the command with a special character attached �, obviously the shell ...
3
votes
2answers
42 views

Why alias inside function does not work?

See the code below: a()(alias x=echo\ hi;type x;alias;x);a I have an alias inside a function, I do not want to change the external environment (that is why I am using () instead of {}), even the ...
0
votes
1answer
19 views

Terminal sandbox commands

I was wondering if there's a way to run shell commands that affect only a certain directory and its subdirectories. I'm using PHP and I want to make an app that allows the user to execute shell ...
2
votes
2answers
54 views

How to return 0 if a pattern is matched from a file? [duplicate]

I have a binary that repacks android kernel (not mkbootimg). I'm making a script to automate the process. I don't want any output on the screen. So I have redirected the output to a file named ...
1
vote
1answer
37 views

Equivalent of Java's String.getBytes() in Unix Shell (Cygwin)

Let's say I convert my string into byte array. byte[] byte sUserID.getBytes(“UTF-8”); //Convert User ID String to byte array Now I need to write a script on Shell that will have exactly the ...
3
votes
2answers
185 views

How to get UUID of filesystem given a path?

I am handed a path of a directory or a file. Which utility/shell script will reliably give me the UUID of the file system on which is this directory/file located? By UUID of file system I mean the ...
1
vote
1answer
12 views

Understanding directory symlinks traversals and the parent directory

Let's say you have directories /dir1 and /dir2/linked, where the later is a symlink to the former. When you cd to linked and pwd, you get the output /dir2/linked. If you then cd .., you'll be put on ...
2
votes
1answer
62 views

bash find: get directory of found file

I have a parent folder named "parent_folder" with a lot of subfolders, in these subfolders is a file named "foo.mp4". I can find these files easily by doing this: mymacbook:parent_folder username$ ...
-2
votes
0answers
26 views

How to create symbolic link to a directory with custom name

I want to create a sym link from the source name TEST to the destination name NAME if i give ln -s TEST /NAME - its going to create the Folder in the /NAME with TEST name but i want to get as NAME ...
0
votes
1answer
23 views

UnixWare 7 fails to pass variable to Linux

I'm new to Bash and I have a problem that find difficult to solve, may be easy for some. I have a really old SCO UnixWare 7 system with no SSH only RSH available. SCO doesn't exist anymore , I ...
1
vote
1answer
25 views

runtime errors, where do they come from?

When a program is executed from the command line (terminal) and there is a runtime error causing the program to seg-fault/coredump where is the runtime error message come from? Is there documentation ...
0
votes
4answers
99 views

How do i change the case (upper and lower case) of strings in my variable?

"Enter test: " read test if [[ $test == "a" ]]; then echo "worked" else echo "failed" fi It's a simple illustration of test i'm doing, but if i enter "A", it will fail, is there anything i ...
-2
votes
2answers
30 views

What is a simple example where the use of the command line is unavoidable or better? [on hold]

I want to see a simple example that motivates the use of the Linux command line. Like I want to see an example where the use of the command line will do it in seconds and on GUI , it will take you ...
3
votes
3answers
139 views

Piping a script with “read” to bash

I need to run a script by piping it through bash with wget(rather than running it directly with bash). $ wget -O - http://example.com/my-script.sh | bash It's not working because my script has read ...
12
votes
3answers
709 views

Any reason to use or teach `…` substition for new development?

It is my understanding that the more modern $(...) command substitution syntax is preferred over the old '`'-based syntax, due to easier and less error-prone nesting and escaping syntax. Further, it ...
2
votes
2answers
27 views

“dpkg -l” receives shell wildcard character?

In a bash shell where I have globbing enabled if I execute ls -l *ou*, then shell should pass out.dot and out.png as arguments to ls, i.e. ls never sees the * character. However, looks like in case of ...
1
vote
7answers
171 views

Remove a specific extension from all the files in a directory

I have a couple of files with ".old" extension. How can I remove the ".old" extension without remove the file? I can do it manually but with more work: mv file1.key.old file1.key mv ...
-2
votes
1answer
27 views

How to use both && and || operator in shell script [on hold]

chkline="Hello world" lastline1=`tail -1 test4.scrn` lastline2=`tail -1 test5.scrn` if [[ ! -f test.scrn && ! -f test2.scrn && ! -f test3.scrn ]] || [ "$lastline1" != "$chkline" ] || [ "$lastline2" ...
1
vote
1answer
13 views

difference between “ip link set” and “disconnect / reconnect” in the GUI?

I've got an Ubuntu 14.04 guest installed in virtualbox. Often when the host machine changes networks or is suspended and restarted, the guest VM loses network connectivity. I can reliably get it ...
2
votes
2answers
169 views

Can I create, set permissions, and write to a file with a single Unix command?

I want to speed up creation of user accounts on some Linux VMs that I am creating, and wondered if I could simplify the process of writing to the new user's ~/.ssh/authorized_keys or ...
0
votes
3answers
42 views

Diff between (x=100) and { x=100; }?

Can some one please explain the below statements? $ x=50 $ (x=100) #here the code executes only with in the subshell. when subshellexecution done then the x value is returned to its original ...
0
votes
2answers
16 views

How do I tell GCC and Clang to look at /usr/local/cuda for include/libs?

I have installed CUDA on my system, but seems like its files are not being found by libraries that depend on it. What should I append to my .bashrc in order for both GCC and Clang to look on the ...
4
votes
5answers
228 views

How do you interact with a file named “!!”? [duplicate]

Out of rage, I quit vim by using :wq!!!. This created a file named !!. Given that !! references the previous command, attempting to interact with it yields interesting results. I tried rm ./!! and ...
2
votes
1answer
187 views

How to get binary representations of strings in Shell?

I'm using openssl dgst -sha1 -binary to get hash values of my strings in binary format. (I'm using -binary flag because my version of openssl adds "stdout" before each hash value on default output, ...
1
vote
2answers
73 views

How do I get command name of the last executed command?

Example: I type man ls, than I want to get man only. By using !! I can get man ls but how do I get man?
0
votes
2answers
22 views

how to know which device was open

is there any shell command, can let me know, current open device or device already in operation. For example, I use minicom to open a device /dev/ttyUSB0 or /dev/ttyS0, after I use program open this ...
0
votes
0answers
46 views

Bash shell scripting check while comparing 2 files [closed]

I have 2 files File 1 abc cde efg hij jkl File 2 abc ( * ) ( * ) ( * ) -- without the braces efg (*) hij -- without braces () () lmn --- without braces Now, while comparing both files line ...
3
votes
1answer
50 views

Mac OS X combine cp and cat to sequentially copy and rename files in list

I am using a MacBook Pro OS X 2013 model. I have a list of filenames in a text file named list.txt separated by line breaks list.txt exactly like this, but this list is going to be long e.jpeg ...
0
votes
1answer
34 views

timeout pipeline

I want to execute these two timeout command on the same command but with a different time and instructions. So timeout --signal=SIGINT 5s command timeout --signal=SIGKILL 10s command How to append ...
3
votes
2answers
108 views

Assign specific line from a variable to another variable

I would like to take a specific line from a variable to another variable. I tried this but it doesn't work: c="1.apple 2.banna 3.peach" read "Please choose fruit [1-3]:" t a=$c | awk "NR==$t" echo ...
1
vote
1answer
39 views

Using cURL, How can I fetch a numerical string which contains commas and spaces and convert such to a NON COMAFIED string [duplicate]

Example: Google's Outstanding Shares are 670,000,000 and this value is collected in a txt file from Yahoo Finance API using the below script. The issue is; that numbers WITH commas or spaces are ...
2
votes
3answers
92 views

Is it possible to add a function within a function?

function update_profile { echo "1. Update Name" echo "2. Update Age" echo "3. Update Gender" echo "Enter option: " read option case $option in 1) update_name ;; ...
3
votes
1answer
19 views

Redirection with nested commands

I am running a $command, in a instance of a screen, as a different user. It's run by the equivalent of this command (more detailed at bottom): su $USERNAME -c "screen -dmS $SCREENNAME $COMMAND" and ...
4
votes
2answers
64 views

status check for sleep command

I have run sleep command in background as follow , How can I know the status of execution ..? Command sleep 2d ; find /home/disk1/ -exec touch {} \; & How can I know that its executed for 1 ...
-2
votes
0answers
27 views

how to get out of PID and port of Solaris 9

Server and the port list are taken from a file "demo", I need the port's process ID to run the ps command. #!/bin/bash while read -r -u10 server port line do echo ========== server: "$server" port: ...
0
votes
1answer
39 views

How could I include a variable in a here document?

I am trying to use a user-defined global variable in a cat <<eof>> filename situation, but it's not working. I found what I want in simple cat << eof examples on this forum, which ...
1
vote
1answer
29 views

using script function rather than keyboard input

I'm writing a shell script to change a user's password. I tried to use the passwd command, but that command always asks for the old and new passwords to be typed; it won't accept them from my script. ...
2
votes
2answers
23 views

variable substitution in CLI and for loops

I am pretty sure this has been asked already in some form, I just cannot come up with a good find to search it. I want to have a script that do things N times and to which I can pass as a variable ...
0
votes
1answer
32 views

unable to read the output to run the next command [closed]

When this script is executed I get the PID. Now I want to read the output "PID" and run the next command in this way: ps -ef | grep -i PID ps -ef | grep -i PID while read -r -u10 server port ...
2
votes
3answers
42 views

How to enter the condition to check 0 or more than 0 in case

I am trying to use case to run this function if [[ $input -gt 0 || $input -eq 0 ]]; Is it possible to put in case to test the input for greater than 0 or equal to 0, or even 0 and less than 0, in ...
2
votes
1answer
39 views

Is there any way to check email sent success acknowledgement?

I need to send the generated CSV files on regular intervals using script. I am using UUENCODE and mailx for the same. But i need to know that is there any method/way to know that email sent ...
2
votes
0answers
45 views

“Restart” a process in the same terminal?

I put "restart" in quotes because the following question on SO illustrates what I'm trying to do: http://stackoverflow.com/questions/27957091/restarting-a-process-in-the-same-linux-terminal I'm ...
1
vote
1answer
39 views

How to remove message when opening terminal/solve?

I am receiving the below message whenever I open the terminal. Repository u'ffmulticonverter_stable': Error parsing config: Error parsing "baseurl = u'ppa:ffmulticonverter/stable'": URL must be ...
5
votes
2answers
176 views

If any spawned child processes fail, kill all and exit

In my script I split up a data set into input_aa, input_ab, etc. Then, I run each through the same Python script, as such: # Execute program on each split file for part in input_*; do python3 ...
5
votes
2answers
152 views

Two-words argument in shell script

I have a problem with a shell script. It is supposed to read arguments: index, date, time1 (the beginning of the interval), time2 (the end of the interval). It should count how many times the ...
2
votes
1answer
59 views

Can lightdm/gnome/compiz use bash instead of sh?

On my Ubuntu 12.04 logging in is handled by the lightdm which starts a gnome-session for the user which starts a compiz instance which then starts the applications the user clicks on. Somewhere in ...