How can I maintain line breaks in body text with mailx when sending attachments?

894

Unquoted newlines in command lines get treated as spaces; that's why you can say things like

command1  &&
command2

Well, sometimes unquoted newlines get treated like semicolons.  But, when you say

echo `cat ${log}`

all the newlines in the log file get turned into spaces.  You could fix this by saying

echo "`cat ${log}`"

but why not just say

cat ${log}

?

Share:
894

Related videos on Youtube

Malik Manseur
Author by

Malik Manseur

Updated on September 18, 2022

Comments

  • Malik Manseur
    Malik Manseur almost 2 years

    It`s been few days that I want to implement a ListView containing Spinners. I am really new to android, so going from forum to forum, I managed to make something work. The only problem I have is the spinners when scrolling down on my real device, their values are lost or behave weirdly (sometimes they are reset, some other time the last element takes the value of the first one ..etc) When I read about that I found out, that android recycles views, so I am trying to use this concept. Could you please either show me the right approach, or tell me what is the wrong thing I am doing. The error I get is the following: 04-27 19:43:09.649: E/AndroidRuntime(7530): java.lang.NullPointerException 04-27 19:43:09.649: E/AndroidRuntime(7530): at com.example.mysqlconnection.MyCustomeArrayAdapter.getView(MyCustomeArrayAdapter.java:106)

    Where line 106 corresponds to: holder.Spin.setSelection((Integer) (holder.Spin.getTag()));

    Thank you very much.

    list_item.xml android:orientation="horizontal" >

    <!-- Product id (pid) - will be HIDDEN - used to pass to other activity -->
    <TextView
        android:id="@+id/pid"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" />   
    
    <!-- Name Label -->
    <TextView
        android:id="@+id/name"
        android:textIsSelectable="true"        
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:paddingTop="6dip"
        android:paddingLeft="6dip"
        android:textSize="17sp"
        android:textStyle="bold"/> 
    
    <Spinner
        android:id="@+id/presence"          
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:entries="@array/presence_list"
        android:prompt="@string/presence_prompt"/> 
    

    public class MyCustomeArrayAdapter extends ArrayAdapter> {

    private static final String TAG_PID = "EnfantId";
    private static final String TAG_NOM = "Prenom";
    
    HashMap<String, String> hm = new HashMap<String, String>();      
    SpinnerContent data[] = null;    
    int[] anArray;
    
    Context context; 
    
    int layoutResourceId;
    ArrayList<HashMap<String, String>> localList;
    LayoutInflater inflater;
    
    public MyCustomeArrayAdapter(Context pContext,  int layoutResourceId, ArrayList<HashMap<String, String>> list) {
        super(pContext, layoutResourceId, list);
    
        this.context = pContext;
        this.layoutResourceId = layoutResourceId;
    
        this.localList = new ArrayList<HashMap<String, String>>();
        this.localList.addAll(list);
        inflater = (LayoutInflater)    context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        data = new SpinnerContent[20];
        anArray = new int[20];
    
    }
    

    @Override public View getView(final int position, View convertView, ViewGroup parent) {

       View row = null;   
       final SpinnerHolder holder;     
    
       if(convertView == null)
        {                   
            row = inflater.inflate(layoutResourceId, null);
    
            holder = new SpinnerHolder();
    
            holder.name = (TextView)row.findViewById(R.id.name);
            holder.pid = (TextView)row.findViewById(R.id.pid);
            holder.Spin = (Spinner)row.findViewById(R.id.presence);
            holder.Spin.setOnItemSelectedListener(new OnItemSelectedListener(){
                @Override
                public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int SpinPosition, long id) {
    
                    holder.Spin.setTag(SpinPosition);
                }
    
                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub
                }   
            });
    
            row.setTag(holder);
        }
        else
        {
            row = convertView;
            holder = (SpinnerHolder)row.getTag();
        }
    
       hm = localList.get(position);
    
       holder.pid.setText(hm.get(TAG_PID));
       holder.name.setText(hm.get(TAG_NOM));     
    
       holder.Spin.setSelection((Integer) (holder.Spin.getTag()));
       return row;
    }
    
    private class SpinnerHolder
    {
        TextView name;
        TextView pid;
        Spinner Spin;
    }
    

    }

  • Malik Manseur
    Malik Manseur about 11 years
    Thank you buptcoder, it solves the problem of Null pointer, but I still have the problem of my spinner change value when I scroll up un down! Any Clue.
  • buptcoder
    buptcoder about 11 years
    I think the because you re-use the spin, so you get the duplicate values.
  • Malik Manseur
    Malik Manseur about 11 years
    thank you again, but I cannot understand how to go without re-using the same spinners. Let me explain: If I dont scroll in my device every spin has its value and everything is great. As soon as I scroll down the rows that go out of scope of the view will have random behavior. the values sometimes are reset sometimes they take the values used by other spinners. I am really struggling with this ones since days.
  • user3756852
    user3756852 over 9 years
    Thank you for the response! Adding double quotes fixed it. Removing the back ticks didn't work. I had tried that before and it just prints the file path of the log as the body of the email. But the double quotes did it! Thanks again!
  • G-Man Says 'Reinstate Monica'
    G-Man Says 'Reinstate Monica' over 9 years
    I'm glad I was able to provide a solution that helped you, but … are you sure you copied my last command exactly? I didn't say echo ${log} or echo cat ${log} (which is what you wrote in the first version of your question). I said cat ${log}, with no echo. (Although I would actually advise cat "${log}", to be safer. You should always quote shell variables unless you have a good reason not to, and you're sure you know what you're doing. By contrast, while braces can be important, they're not as important as quotes, so cat "$log" is good enough. Similarly, "$file1", etc.)