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)

1
vote
1answer
39 views

Save and restore terminal tabs with custom tabs title

I have a Terminal window with a dozen named tabs open *(gnome-terminal) I would like to save the current configuration and have it restored with names and directories. Is there a way to do this? I've ...
1
vote
1answer
53 views

Read a character from an x-y coordinate on the screen

Is there a way in bash to read a character from an x-y coordinate on the screen? This command would be something similar to cget 12 30 which would return the character at the 12th row and 30th ...
0
votes
0answers
30 views

Pass a function arguments?

How would you make a function that gets arguments? function arg_example { arg "c" # This is imaginary but it would return 'true' if it found the argument -c. did_find_arg=$? # Get the ...
0
votes
1answer
82 views

Opening a socket in Kali Linux using bash scripts

I know how to open a TCP or UDP socket in Ubuntu, with the following command : exec 3<>/dev/tcp/google.com/80 for example: we can open a TCP socket on port 80, but in Kali Linux there's no ...
10
votes
5answers
825 views

How to get the last N files in a directory?

I have many files that are ordered by file name in a directory. I wish to copy the final N (say, N=4) files to my home directory. How should I do it? cp ./<the final 4 files> ~/
0
votes
2answers
39 views

The best way to add Unix Shell variables to CURL GET request

Let’s say I use curl –X GET command with the following link: “$WEBSITE_URL/ACTION_NAME/ACTION1;id=$ID?Command=TEST&id1=$ID1&id2=$ID2&id3=$ID3” As you can see, there are some $variables ...
11
votes
3answers
692 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 ...
19
votes
6answers
1k views

Do we have more history for cd?

cd - can move to the last visited directory. Can we visit more history other than the last one?
8
votes
2answers
446 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 ...
3
votes
2answers
116 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
2answers
190 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.
0
votes
2answers
47 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 ...
0
votes
1answer
191 views

Making A Shell Script To Write To XML File

I am writing a shell script to make writing my RSS a whole lot easier. Right now I am stuck at how to properly edit my files. See, I want the program to take in data from me, and then save those to ...
3
votes
3answers
181 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 ...
1
vote
1answer
20 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
108 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$ ...
0
votes
1answer
37 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 ...
0
votes
4answers
121 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 ...
3
votes
2answers
54 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 ...
1
vote
1answer
60 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 ...
0
votes
1answer
32 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 ...
3
votes
2answers
216 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 ...
2
votes
2answers
69 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
2answers
146 views

multiple conversion bam to bed using bedtools

I have ten .bam files (bioinformatic format) and I would like to convert it to 10 .bed files, but for this conversion I need to use special command bedtools bamTobed -i (input file) > output ...
1
vote
1answer
30 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 ...
12
votes
2answers
11k views

how to output text to both screen and file inside a shell script?

Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file ...
19
votes
10answers
8k views

Object-oriented shell for *nix

Preface: I love bash and have no intention of starting any sort of argument or holy-war, and hopefully this is not an extremely naive question. This question is somewhat related to this post on ...
-2
votes
2answers
41 views

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

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 ...
1
vote
1answer
1k views

Deleting Non-empty Directory with smbclient

How can I remove a non-empty directory with smbclient? I have tried the following: 1) rm Result: NT_STATUS_NO_SUCH_FILE listing [dir_path] 2) recurse;rm Result: No Error but also nothing ...
92
votes
10answers
107k views

Colorizing your terminal and shell environment?

I spend most of my time working in Unix environments and using terminal emulators. I try to use color on the command line, because color makes the output more useful and intuitive. What options exist ...
2
votes
2answers
30 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
190 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 ...
43
votes
1answer
1k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
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 ;; ...
21
votes
2answers
4k views

What is the bash shortcut to change to the previous directory?

Sadly, I only learned about this last year by stumbling upon it randomly on the internet. I use it so infrequently that I always forget what it is by the time I need it again. How do you change to ...
2
votes
2answers
180 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 ...
11
votes
2answers
1k views

What is the difference between shell, eshell, and term in Emacs?

In Emacs I can run a shell using following commands - M-x term M-x shell M-x eshell What is the difference between these three?
35
votes
5answers
4k views

What are the fundamental differences between the mainstream *NIX shells?

What are the fundamental differences between the mainstream *NIX shells and what scenarios might prompt you to use one over the other? I understand that some of it probably comes down to user ...
1
vote
2answers
78 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?
1
vote
1answer
19 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 ...
6
votes
2answers
352 views

Is it possible to use shell parameter variables ($1, …, $@) directly in CLI?

Sometimes it is necessary to emulate and verify the above variables in small examples and then can be copied immediately to some script, etc. I tried to solve by using a simple example in the ...
0
votes
3answers
44 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 ...
2
votes
1answer
209 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, ...
0
votes
2answers
24 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 ...
1
vote
1answer
52 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 ...
0
votes
2answers
23 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
1answer
1k views

How to execute Netscaler commands through a remote machine via SSH connection

I have been trying to execute some NetScaler commands like "bind" & "unbind" through a Linux Box via an SSH Connection. Now the Problem is, Manually we are able to enter & execute commands on ...
3
votes
1answer
87 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 ...
1
vote
3answers
61 views

How to negate a case pattern

How add I add the condition in case whereby if it does not detect the required conditions, it will execute the command. My code: case $price in [0-9] | "." | "$") echo "Numbers, . , $ Only" ...
0
votes
1answer
42 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 ...