I'm trying to check if a machine is a ThinkPad or not using something like this:  sudo dmidecode | grep ThinkPad   I want the end result return true or false (or 1/0).   I'm thinking the solution might be something like this:  sudo dmidecode | grep -c ThinkPad | test xargs -gt 0   But I'm not sure how to properly use xargs here.
70837
As a part of this script, I need to be able to check if the first argument given matches the first word of file. If it does, exit with an error message; if it doesn't, append the arguments to the file. I understand how to write the if statement, but not how to use grep within a script. I understand that grep will look something like this  grep ^$1 schemas.txt   I feel like this should be much easier than I am making it.  I'm getting an error "too many arguments" on the if statement. I got rid of the space between grep -q and then got an error binary operator expected.   if [ grep -q ^$1 schemas.txt ] then         echo "Schema already exists. Please try again"         exit 1 else         echo "$@" &gt;&gt; schemas.txt fi
99287
Unable to scan with hp scan-jet 200. When I type lsusb command in terminal it shows the scanner details.  I opened the simple scan which displays no scanners found, and x sane image scanners also displays the same error.
90502
I am using zsh and I have defined few utility shell function in some shell scripts, few of them called from ~/.zshrc, so let's assume that we don't know the location of these functions. One function is:  function k.pstree.n {     if [ "$1" != "" ]     then         pstree -p | grep -C3 "$1"     else         printf "  Please specify the name of the process you want to show!\n"     fi }   How can I print the code of that shell function?  I can think of a search &amp; grep like:  find $(pwd) -name "*sh*" -type f -printf "\"%p\"\n" | xargs grep -C5 "k.pstree.n"   but this assumes that I roughly know the location which is not true here.
110795
I am trying to run a script located in usr/local/bin/ when I connect an external monitor to my laptop. I have tried to add a new udev rule but that did not work. I created a new file in /etc/udev/rules.d called vga-monitor-connect.rules. The contents of the file were   SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/panel-fix"   I took the line from   After searching online I also tried the following rule  KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/rumesh/.Xauthority", RUN+="/usr/local/bin/panel-fix"   However this didn't work either.  I have run the script manually and I can confirm that it works so it is not a problem with my script.  I also want to make it clear that I do not know much about udev so the rule I have used may be wrong. If anyone knows the proper rule for my problem please leave an answer.  My graphics card is an Intel GM965 integrated chipset
4270
Just looking for the difference between   2&gt;&amp;- 2&gt;/dev/null |&amp; &amp;&gt;/dev/null &gt;/dev/null 2&gt;&amp;1   and their portability with non-Bourne shells like tcsh, mksh, etc.
28751
How can get the BIOS version of my motherboard?  The command dmidecode gives you some information about the BIOS, but I can't find what I need...    I tried dmidecode command before asking and I didn't find what I needed - I want only the BIOS version and nothing else in the output.
59298
Is there a way to check to see if a pid corresponds to a valid process? I'm getting a pid from a different source other than from os.getpid() and I need to check to see if a process with that pid doesn't exist on the machine.   I need it to be available in Unix and Windows. I'm also checking to see if the PID is NOT in use.
10234
My problem:  I'm writing a bash script and in it I'd like to check if a given service is running.  I know how to do this manually, with $ service [service_name] status.  But (especially since the move to systemd) that prints a whole bunch of text that's a little messy to parse. I assumed there's a command made for scripts with simple output or a return value I can check.  But Googling around only yields a ton of "Oh, just ps aux | grep -v grep | grep [service_name]" results. That can't be the best practice, is it? What if another instance of that command is running, but not one started by the SysV init script?  Or should I just shut up and get my hands dirty with a little pgrep?
119464
Suppose I do     grep "MyVariable = False" FormA.frm     ... result1     grep "MyVariable = True"  FormA.frm     ... result2   How to write the grep command so that I can say something like     grep "MyVariable = False" OR "MyVariable = True" FormA.frm
16499
If yes, on which operating system, shell or whatever?  Consider the following java program (I'm using java just as an example, any language would be good for this question, which is more about operation systems):  public class ExitCode {     public static void main(String args[]) {         System.exit(Integer.parseInt(args[0]));     } }   Running it on Linux and bash, it returns always values less equal 255, e.g. (echo $? prints the exit code of the previous executed command)  &gt; java ExitCode 2; echo $? 2  &gt; java ExitCode 128; echo $? 128  &gt; java ExitCode 255; echo $? 255  &gt; java ExitCode 256; echo $? 0  &gt; java ExitCode 65536; echo $? 0     EDITED: the (only, so far) answer below fully  explain what happens on UNIXes. I'm still wondering about other OSes.
64749
I'm interested in using my laptop trackpad as a drawing tablet, i.e. using absolute rather than relative coordinates, similar to  for OSX.  The same question was asked in  in May 2010, but the question was never answered. I'm wondering if this has been done on Linux. I'm also trying to figure out which search terms to use. I searched for 'linux laptop touchpad absolute mode', and came up with  which put the trackpad in absolute mode. but I'm really looking for a program which uses the absolute positions rather than a driver setting.
64991
Suppose I want to compare gcc version to see whether the system has the minimum version installed or not.  To check the gcc version, I executed the following  gcc --version | head -n1 | cut -d" " -f4   The output was  4.8.5   So, I wrote a simple if statement to check this version against some other value  if [ "$(gcc --version | head -n1 | cut -d" " -f4)" -lt 5.0.0 ]; then     echo "Less than 5.0.0" else     echo "Greater than 5.0.0" fi   But it throws an error:  [: integer expression expected: 4.8.5   I understood my mistake that I was using strings to compare and the -lt requires integer. So, is there any other way to compare the versions?
120204
I am using gedit text editor with embedded terminal in ubuntu 12.04. I'm trying to search for some text using grep. I want to search for this line of code   'type' =&gt; 'select'   I tried:  grep -r '\'type\' =&gt; \'select\''  But grep didn't return any results.  So can someone kindly tell me how to search for the code above?
121065
How can I check if /bin/x86_64/bin/ls is a directory in a bash shell script  Here is what I tried:  #!/bin/bash  if [ $# -eq 2 ]; then     if [[ "$1" = /* ]]     then     cd ./bin/x86_64/bin/ls         if [ -d "$1" ]; then             echo "ok"             i="$1"             echo $i         else             echo "error2"             exit         fi     else         echo "error"         exit     fi fi
52281
While trying to follow , I encountered the following error while attempting what seems like a simple sudo edit operation:  $  sudo gedit /var/lib/dpkg/status  ** (gedit:14898): WARNING **: Command line `dbus-launch --autolaunch=0bd873023a78bdb34ca1b9650000000b --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n Cannot open display:  Run 'gedit --help' to see a full list of available command line options.   Running the same without sudo correctly launches gedit, but of course without editing ability. Does anyone have any idea what is going on?
66338
I want to know if there's any way to check if my program can output terminal output using colors or not.   Running commands like less and looking at the output from a program that outputs using colors, the output is displayed wrong, like  [ESC[0;32m0.052ESC[0m ESC[1;32m2,816.00 kbESC[0m]  Thanks
79804
I need to run shell script contains Xdotool codes in /home/z/Desktop/tempo/run.sh. I've tried many ways of DISPLAY=:0 but always not works.  I've tried each of below codes, and not works:  * * * * * export DISPLAY=:0 cd /home/z/Desktop/tempo; ./run.sh * * * * * export DISPLAY=:0; cd /home/z/Desktop/tempo; ./run.sh * * * * * export DISPLAY=:0 &amp;&amp; cd /home/z/Desktop/tempo; ./run.sh * * * * * DISPLAY=:0 cd /home/z/Desktop/tempo; ./run.sh * * * * * DISPLAY=:0; cd /home/z/Desktop/tempo; ./run.sh * * * * * DISPLAY=:0 &amp;&amp; cd /home/z/Desktop/tempo; ./run.sh   Running directly also not works:  * * * * * export DISPLAY=:0 xdotool mousemove 20 20 * * * * * export DISPLAY=:0; xdotool mousemove 20 20 * * * * * export DISPLAY=:0 &amp;&amp; xdotool mousemove 20 20 * * * * * DISPLAY=:0 xdotool mousemove 20 20 * * * * * DISPLAY=:0; xdotool mousemove 20 20 * * * * * DISPLAY=:0 &amp;&amp; xdotool mousemove 20 20   I always don't see my mouse moving on each line of codes above.  I've also tested Xdotool codes to make invalid website URI request and see the logs. Sadly the logs still blank.